RunCommand in VBA

I wrte a small macro to latout shearwalls for Excel Automation. Works pretty well, however, I got smart and decided to convert a LWPoly to a Region so I could obtain the Area and Centroid of the closed figure. Seemed like this would be easier than Excel calcs. Well after much frustration(I'm really not an Object programmer) I gave up on .SolidCreator and decided to just use the RunCommand("_Region" ...). When it came to query the Area & Centroid I found that mydoc.count still held the LWPolyline, as if the count does not increment with the RunCommand. Is this true? What is a work-around? or sample using SolidCreator? as when using VBA methods to create the counter seems to jive with the dwg DB.Thanks to any that may guide me.

Comments

  • Never Mind. Put a Timer delay after Runcommand and O.K.Not very elegant though. BTW, affinity set to single CPU, thought that would have negated the timinig issue.Still haven't figured how to use solidCreator.addReion(objlist)What is object list, can't I just pass a closed LWPoly?

  • Dear Jerry,you're right, it's not easy getting started with Regions in COM.I wrote a small sample program for you and I have to admit I stumbled into various pitfalls before I got it working correctly.Anyway, the region code underhere should let you avoid to run commands from within your COM program, which is errorprone because of threading issues. The command queue is processed in a different thread than the COM code, leading to problems to keep your program execution synchronized, e.g. the timer delay that you had to build in.Best regards,Hans De Backer---------------------Sub regiontest() Dim pt As Point Dim poly As Polyline Dim entities(0 To 3) As Object Dim i As Integer Dim pts As Points Set pts = New Points 'create four overlapping squares For i = 0 To 3 Set pt = pts.Add(i + 0, i + 0, 0, 1) Set pt = pts.Add(i + 2, i + 0, 0, 2) Set pt = pts.Add(i + 2, i + 2, 0, 3) Set pt = pts.Add(i + 0, i + 2, 0, 4) Set poly = ThisDocument.ModelSpace.AddPolyline(pts) poly.Closed = True Set entities(i) = poly poly.Delete pts.RemoveAll Next i 'make regions from the squares and union those to 1 region Dim result As Variant result = ThisDocument.ModelSpace.SolidCreator.AddRegion(entities) Dim numRegions As Integer numRegions = UBound(result) - LBound(result) + 1 Dim region_A As Region, region_B As Region Set region_A = result(1) For i = 2 To numRegions Set region_B = result(i) Call region_A.Boolean(vicUnion, region_B) Next i ThisDocument.RegenEnd Sub

  • I really appreciate the time and great code. Really helps me to learn alot. Isn't VBA running in a seperate thread also. Seem's like a routine that would suspend execution while the icad thread processes events would be handy. Of course that would be something beyond VBA, like sending messages to the system.Which brings up the subject of having the icad loading function set the affinity, rather than manually setting each start-up. Would be nice.Thanks alot.

This discussion has been closed.