VisualArq Api AddWindow() accessing protected memory

Hello, I am working on a project using the VisualArq API (C#), and have been slowly getting a grasp on how it is used. I am running into an issue when creating a new window with a custom style…

            //Create a profile from a rectangle
            VA.CurveProfileSize curveProfileSize = new VA.CurveProfileSize();
            curveProfileSize.OuterCurve = new Rectangle3d(Plane.WorldZX, 5.0, 8.0).ToNurbsCurve();
            Guid profileTemplateID = VA.AddCurveProfileTemplate("TestStyle", curveProfileSize);
            
            //Create a style and a profile
            Guid styleId = VA.AddWindowStyle("TestWindowStyle", profileTemplateID);
            Guid profileId = VA.AddCurveProfileTemplate("TestCurveProfileTemplate", curveProfileSize);

            //Assign the profile to the style
            VA.SetOpeningStyleProfileTemplate(styleId, profileId);

            //Add a window using the new style
            Guid openingId = VA.AddWindow(styleId, new Point3d(0,20,0), 0.0);

The error is thrown on the VA.AddWindow(), as “Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
What does work is calling VA.GetAllWindowStyleIds(), and getting the 0th element (the supposed default one), which works. That would be VA.AddWindow(VA.GetAllWindowStyleIds()[0], new Point3d(0,20,0), 0.0);

This is just a portion of some test code that is placing the window on a wall that exists between points (0,0,0), and (0,100,0)

Update: Adding a style this way shows in both the vaWindowStyles command window, and in the properties panel, yet when assigning a default-style created window to the new style, the same “Attempted to read or write…” error occurs.

Version: RhinoCommon 7.6.21127.19001
OS: Windows
Language: C# using VisualStudio

Hi @chris.kinney,

Sorry for the late reply, but we’ve been busy with the release of VisualARQ 2.11.

I’ve checked your code. The first problem is that the profile must by a 2D curve, so you should change your code to:

// Create a profile from a rectangle
VA.CurveProfileSize curveProfileSize = new VA.CurveProfileSize();
curveProfileSize.OuterCurve = new Rectangle3d(Plane.WorldXY, 5.0, 8.0).ToNurbsCurve();
curveProfileSize.OuterCurve.ChangeDimension(2);
Guid profileTemplateId = VA.AddCurveProfileTemplate("TestStyle", curveProfileSize);

If you want to use a rectangular profile, it is better to just use a parametric rectangular profile, so its dimensions will be editable. Here is a sample that also adds some components to the window style:

// Create a rectangular window style with a frame and two leaves
Guid styleId = VA.AddWindowStyle("TestWindowStyle", profileTemplateId);

// Set rectanguar profile
VA.SetOpeningStyleProfileTemplate(styleId, VA.GetRectangularProfileTemplate());

// Add a frame
Guid frameId = VA.AddWindowFrame(styleId, "Frame");
VA.SetOpeningFrameWidth(frameId, 0.01);

// Add leaf 1 with glass
Guid leaf1Id = VA.AddWindowLeaf(styleId, "Leaf 1");
VA.SetOpeningLeafSize(leaf1Id, 0.6);
VA.AddWindowLeafGlass(leaf1Id, "Glass");

// Add leaf 2 with glass
Guid leaf2Id = VA.AddWindowLeaf(styleId, "Leaf 2");
VA.SetOpeningLeafSize(leaf2Id, 0.4);
VA.AddWindowLeafGlass(leaf2Id, "Glass");

// Add a window using the new style
Guid openingId = VA.AddWindow(styleId, new Point3d(0, 20, 0), 0.0);

Regards,

Enric

1 Like