PDA

View Full Version : 2D Polygon generation w/ VBA



joeposton
2004-12-06, 09:35 PM
When I use ADDLINE... then use UPDATE... see MODIFICATION IMMEDIATELY...
But when I use SendCommand... then use UPDATE... does not act IMMEDIATELY...
BUT when I go back to the drawing... Modifications are PRESENT...
NEED to have IMMEDIATELY RESULTS for students to see the 2-D generations...
'=========================================================
Private Sub CommandButton4_Click()
' This example adds an DECAGON in model space... 10 SIDES POLYGON...
Dim alineObj As AcadLine
Dim startline(0 To 2) As Double '0=X...1=Y...2=Z
Dim endline(0 To 2) As Double
'================================================
Set acadObj = GetObject(, "AutoCAD.Application") 'Set up old OBJECTS..
Set AcadDoc = acadObj.ActiveDocument 'Set up old DOCUMENTS...
'================================================
' Define data for new DECAGON base (box) '====== Begin at UCS Point =====
ThisDrawing.SendCommand ("_POLYGON 10 e 0 2 ") 'Draws Polygon Perfectly
acadObj.Update 'Will NOT UPDATE
ThisDrawing.Application.ZoomExtents 'ZOOMS PERFECT
'===================END OF PROGRAMMING =======
End Sub

RobertB
2004-12-07, 01:05 AM
That is the problem with SendCommand. What version of AutoCAD are you running? It would be better to calculate the points given the desired number of sides and use the AddLightweightPolyline method. Tedious, yes, but better than SendCommand.

Otherwise, you might try the hacks of placing the SendCommand in its own procedure, along with a DoEvents statement.

joeposton
2004-12-07, 02:56 PM
THANKS... I will try the addlightweightpolyline methods... GREAT...

ntaylor
2004-12-07, 10:30 PM
Otherwise, you might try the hacks of placing the SendCommand in its own procedure, along with a DoEvents statement.
I hadn't seen or thought of that hack it may be useful when things get desperate.

Regards - Nathan