Jump to content

VBA - Draw a polyline after run macro


magnus2005

Recommended Posts

Hello,

I am wondering if it is possible to do macro:

1.start module

2. Drawing polyline in auto cad (like normal you draw poly in cad using pline comannd)

3. End drawing poly

4. Take coords of new poly and change colors.

 

It is example algorithm but its show you how I want to create polyline. Instead of put poly using coords from variable I want normally draw poly to use function i.e orto or sample to see shape. My program will be to draw poly and after poly will be preparated to draw. It is possible to do it way I want?

Edited by magnus2005
Link to comment
Share on other sites

It may be possible to simulate the real-time, dynamic feedback that you described by continually adding lines, and using GetPoint with the previous Line’s endpoint as a Base. At the end, the lines could be erased and the proper polyline created.

 

One major drawback would be if you wanted to account for arcs – I don’t think the Arc/Bulge creation sequence of the polyline command could be re-created via VBA.

Link to comment
Share on other sites

If you have a list of points ((12 34)(56 78) .... this will draw a pline

 

; list is coordsxy
(command "_PLINE")
(while (= (getvar "cmdactive") 1 ) 
(repeat (length co-ordsxy)
(command  (nth (setq x (+ x 1)) co-ordsxy))
)

Link to comment
Share on other sites

I know how to create polyline if I have list of point. Thing is I want to run command pline so that user can draw poly. Getting point is not enough for me, I need to see what I am drawing. Getting points is useless because you can choose point about different coordinations i.e I want to draw vertical line but second point choosen has different x than first.

Link to comment
Share on other sites

My VBA is rusty so I'm not going to take this very far (only as far as drawing the lines). Here is some code illustrating what I suggested above.

 

Sub Example_AddLine()

Dim strPrompt As String
Dim dblPt() As Double
Dim dblNextPt() As Double
Dim blnTrue As Boolean
Dim lineObj As AcadLine

strPrompt = "Get First Point: "
blnTrue = True
  With ThisDrawing.Utility
     On Error Resume Next
     dblPt = .GetPoint(, strPrompt)
     If Err.Number <> 0 Then Exit Sub

     
   Do While blnTrue = True
       strPrompt = "Get Next Point: "
       dblNextPt = .GetPoint(dblPt, strPrompt)
       If Err.Number <> 0 Then blnTrue = False
       Set lineObj = ThisDrawing.ModelSpace.AddLine(dblPt, dblNextPt)
       dblPt = dblNextPt
   Loop
       
   On Error GoTo 0
   End With

End Sub

 

The GetPoint method will respect the Ortho setting during input, though not if an object snap is used. You would have to code your own logic if that combination is to be addressed.

 

See screencast of code in action.

https://screencast.autodesk.com/main/details/46bb9fdd-e8b6-49c7-91de-f7ea2f113ef7

Link to comment
Share on other sites

I'm sorry but you missunderstand me. Your advice is very helpfull and thank you for it. But I 'm disappointed to vba cannot do that.

Edited by magnus2005
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...