Jump to content

VBA Autocad: How to find lines?


Recommended Posts

I'm trying to write a VBA code that searches in a general drawing all lines that have a specific length and slope. Then, every time it finds that line in the drawing, it will write next to a specific text, for example "line". Do you think it's possibile? Any idea? Thanks

Link to comment
Share on other sites

In principle what you want to do is perfectly possible.


You search the current drawing filtering on lines to create a selection set. Then loop through the selection set and write your text at your desired position.

Link to comment
Share on other sites



Dim FilterDXFCode(0) As Integer
Dim FilterDXFVal(0) As Variant

FilterDXFCode(0) = 0
FilterDXFVal(0) = "LINE"

Set SS = ThisDrawing.SelectionSets.Add("Linelens")
SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal
For Cntr = 0 To SS.Count - 1

'now get the length etc and do something

As lisp

(setq ss (ssget (list (cons 0 "Line"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname  ss (setq x (- x 1)))))
(vla-get-length obj)
(princ "\n")

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.

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...