AddRegion
Dim App As AcadApplication, Doc As AcadDocumentSet App = GetObject(, "BricsCADApp.AcadApplication")Set Doc = App.ActiveDocumentDim plineObj(0) As AcadLWPolylineDim RegionObj As AcadRegionDim PolyPoints() As DoubleDim Punkt As DoubleReDim PolyPoints(0 To 9) As DoublePolyPoints(0) = 0PolyPoints(1) = 0PolyPoints(2) = 10PolyPoints(3) = 0PolyPoints(4) = 8PolyPoints(5) = 5PolyPoints(6) = 2PolyPoints(7) = 5PolyPoints(8) = 0PolyPoints(9) = 0Set plineObj(0) = Doc.ModelSpace.AddLightWeightPolyline(PolyPoints)RegionObj = Doc.ModelSpace.AddRegion(plineObj)
When I run this code, the polyline comes and is transformed to a region, but the execution stops with an error. What is wrong?Thank you and have a nice weekendRainer Lothmann
Comments
-
Rainer Lothmann,TryDim RegionObj As Variant
0 -
Johns right, AddRegion() returns an array of regions, so it you want to modify the region(s), you will nee to iterate through the array. (Sorry my VB is a bit choppy so I’m posting C#)
[CommandMethod("test")] public static void test() { try { AcadApplication app = Application.AcadApplication as AcadApplication; if (app == null) { throw new Exception("Could Not Get Application"); } AcadDatabase db = app.ActiveDocument.database; double[] vertex = new double[] { 0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 100.0, 0.0, 0.0, 0.0 }; AcadLWPolyline pline = db.ModelSpace.AddLightWeightPolyline(vertex); object[] pRegion = db.ModelSpace.AddRegion(pline) as object[]; foreach (AcadRegion r in pRegion) { r.color = ACAD_COLOR.acBlue; r.Update(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
0 -
Is this coplanner?
0 -
Dear John and Daniel,thank you for your really fast answer!I tried the following, but I always get the same error:Dim RegionObj as VariantDim RegionObj as ObjectDim RegionObj(0) as ...I always get runtime error '430'Do you have any idea, what to try else?Thank youRainer
0 -
Try this
0 -
oops !
Sub dan()Dim App As AcadApplication, Doc As AcadDocumentSet App = GetObject(, "BricsCADApp.AcadApplication")Set Doc = App.ActiveDocumentDim plineObj(0) As AcadLWPolylineDim pRegions() As AcadRegion 'added thisDim PolyPoints() As DoubleDim Punkt As DoubleReDim PolyPoints(0 To 9) As DoublePolyPoints(0) = 0PolyPoints(1) = 0PolyPoints(2) = 10PolyPoints(3) = 0PolyPoints(4) = 8PolyPoints(5) = 5PolyPoints(6) = 2PolyPoints(7) = 5PolyPoints(8) = 0PolyPoints(9) = 0Set plineObj(0) = Doc.ModelSpace.AddLightWeightPolyline(PolyPoints)pRegions = Doc.ModelSpace.AddRegion(plineObj)End Sub
0 -
Sorry, but I still get error 430.The funny thing is, that it creates the region, so it executes the command, but gives this error. The error says, that this class does not support automation, but it actually does. Is there possibly something missing in the dll? When I look into the Bricscad helpfile, addregion comes as a method of acadblock and it is not underlined. Do I first have to create a block?
0 -
The code I posted runs on my machine with no errors, I suppose the next question would be, what version of Bricscad are you running?
0 -
The BricsCAD Version is 9.2.9 Build 14110VBA is Access 2007 withBricscad DB 2.6 Type Library andBricscad App 1.0 Type Library
0 -
For what its worth I just ran Dan's code myself with the following system configuration.The BricsCAD Version is 9.2.10 Build 14170VBA is Access 2007 with Bricscad DB 2.6 Type Library and Bricscad App 2.6 Type LibraryI too am faced with a dialog saying that the object does not support automation even though the code completes successfully.
0 -
For what its worth mine runs ok.
0 -
John Finlay,which Bricscad version do you use?Should I possibly go to an older version?
0 -
I am using BricsCAD version 9.2.7 and VBA version 6.5.1024
0 -
We found out something new:When we run Daniels code in VBA in Bricscad 'from inside' it works.When we run the same code in Access 'from outside' it brings the errors.The BC dlls are the same.What could be the reason?
0 -
We will try to reproduce this and keep you informed about our findings.Kind regards.
0 -
We could indeed reproduce problems when using an external COM application to add regions. Fixes have been applied, they will be made available in an update release scheduled for the coming days. Thanks to all for your contributions in pinpointing this issue!
0