2D Polygon generation w/VBA

Discussion in 'AutoCAD' started by postonz, Dec 6, 2004.

  1. postonz

    postonz Guest

    IF I use Addline... then UPDATE... see the modifications in drawing... IMMEDIATELY...
    IF I use SendCommand (POLYGON)... then UPDATE... The modifications are NOT IMMEDIATE...
    BUT when I go back to the Drawing... MODIFICATION are THERE... SEE VBA CODE...
    '==============================================
    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
     
    postonz, Dec 6, 2004
    #1
  2. I think the problem is that with some commands SendCommand executes immediately but with a lot they do not execute until the code has finished.

    I see your code is making a 10 sided polgon. How many polygon variations do you need to create? I know it will be a lot more complicated but would it be possible to calculate the corners of the polygon and use the AddLightweightPolyline method.

    Good Luck - Nathan
     
    Nathan Taylor, Dec 6, 2004
    #2
  3. postonz

    Jorge Lopez Guest

    The problem is that SendCommand is asynchronous and is not processing before
    your call Update. If your form is modal it wont execute at all until you
    dismiss it. See if the following works for you:

    Me.Hide ' added to your code

    ThisDrawing.SendCommand ("_POLYGON 10 e 0 2 ") 'Draws Polygon
    Perfectly
    acadObj.Update 'Will NOT UPDATE
    ThisDrawing.Application.ZoomExtents 'ZOOMS PERFECT

    Me.Show 1 ' added to your code

    Basically it just removes the modal dialog and re-displays it. I highly
    recommend you do not use SendCommand whenever possible.

    - Jorge
     
    Jorge Lopez, Dec 6, 2004
    #3
  4. postonz

    postonz Guest

    THANKS... Works for me.. (ME.SHOW 1)... GREAT...
     
    postonz, Dec 7, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.