Auto Generating Lines between imported points using AutoLISP

Auto Generating Lines between imported points using AutoLISP

kevinasims
Observer Observer
4,355 Views
11 Replies
Message 1 of 12

Auto Generating Lines between imported points using AutoLISP

kevinasims
Observer
Observer

I've been trying to automatically generate lines between points using AutoLISP but my lack of experience is putting a stop to that.

 

My company manually places lines between imported points shown below

 

kevinasims_0-1675102669310.png

Turn into

kevinasims_1-1675102731159.png

 

I'm trying to automate this process through lisps. Create line between point 50079 and 50080, create line between 50080 and 50081 and so on. While also preserving x,y,z coordinates. And then conclude once there are no more points to iterate through.

 

Perhaps get autoLisp to see this information. No idea how to get it to though.

kevinasims_0-1675116475720.png

 

 

Eventually I would probably even have it choose a layer of the line based on the layers of the points, and if two layers from the start point and end point do not match, choose layer 0. But that may be something to look into later.

 

I'm wondering if this is at all possible. Thank you!

 

 

 

 

0 Likes
4,356 Views
11 Replies
Replies (11)
Message 2 of 12

Sea-Haven
Mentor
Mentor

Ok simplest answer is a CIVIL package stringing is built in, takes the points looks at the codes and makes a choice add a block at point or string between points. This is a day to day ocurence not something new.

 

String coding has been around since civil software has existed, a home grown version will end up often with spaghetti. 

 

Have a look at Stringer and Civil Site Design, from one supplier, CIV3D being the obvious other option.

 

Start here https://civilsurveysolutions.com.au/

 

Can it be done, yes is answer but its complicated you need lookup lists or library of codes, for CIV3D its Description Key Sets, where I worked we had like 250 codes.

 

There is so much more to string coding common name but various strings use a number 01EB, 02EB the 01 edge of bitumen does not join to 02EB, corner codes two strings meet 03F*05F, close 4 points to make a rectang, and others. 

0 Likes
Message 3 of 12

hippe013
Advisor
Advisor

We can start by getting a selection set of cogo points. Then convert that selection set to a list of cogo points as vla-objects, sort that list by the point number, and then just simply draw a line from point to point. Below is the lisp, the command name is "StringCogo". Let me know if this is what you had in mind. 

 

 

(defun c:StringCogo ( / ss)
  (setq ss (ssget '(( 0 . "AECC_COGO_POINT"))))
  (if ss
    (progn
      (setq li (sc:SortCogoList (sc:SelSet->List ss)))
      (setq ms (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'ModelSpace))
      (setq len (length li) n 0)
      (repeat (- (length li) 1)
	(setq obj1 (nth n li))
	(setq obj2 (nth (+ n 1) li))
	(vlax-invoke-method ms 'AddLine (vlax-get-property obj1 'Location)(vlax-get-property obj2 'Location))
	(setq n (+ n 1))
	)
      )
    )
  (princ)
  )

(defun sc:SortCogoList (li)
  (vl-sort li (function (lambda (p1 p2) (< (vlax-get-property p1 'Number) (vlax-get-property p2 'Number)))))
  )

(defun sc:SelSet->List (ss / n li obj)
  (setq n 0)
  (setq li '())
  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss n)))
    (setq li (append li (list obj)))
    (setq n (+ n 1))
    )
  li
  )

 

 

0 Likes
Message 4 of 12

CodeDing
Mentor
Mentor

@kevinasims ,

 

Tbh, your company should get with the times and start implementing Linework Code Set codes in the field. The additional effort placed on the field crew is SLIGHT in comparison to the burden on the drafter without the linework codes. But I'm not here to bash your company. Just wanted to encourage the useful tools already available to you.

 

In response to your original question.. Civil 3D already has what it sounds like you're asking for... The ability to automatically create a line that connects to many points vs having to enter them (or select them) manually.

 

Civil 3D has Transparent Commands. Of which, it sounds like you could leverage the Point Number or 'pn command.

 

Essentially your workflow will look like this...

- Run the line command you would like to create, such as 3DPOLY.

- When prompted to select a point, you should instead enter the transparent command and hit enter: 'pn

- You will be prompted to "Enter point number:" ...from this prompt you can either enter an INDIVIDUAL point number OR you can enter a RANGE of points numbers. You can then hit enter after entry and your line will automatically be drawn to those point numbers. The entry would look like: 100-105 ...if you would like to start the line on point 100, connect to 101, connect to 102, connect to 103, connect to 104, and finish at 105 (assuming all of those points exist in your dwg).

 

Here's a quick video. Note that I can start and end on whatever point numbers I desire, and also note that I am missing point 103 in my drawing and it recognizes that and carries on to the next available point:

(view in My Videos)

 

0 Likes
Message 5 of 12

druizJ2RUZ
Explorer
Explorer

that's an excellent code, do you know how modify the code to create a single Polyline instead of individual lines?

0 Likes
Message 6 of 12

hippe013
Advisor
Advisor

Yes, of course!

 

See modified code:

(defun c:StringCogoPoly ( / ss li ms pl poly)
  (setq ss (ssget '(( 0 . "AECC_COGO_POINT"))))
  (if ss
    (progn
      (setq li (sc:SortCogoList (sc:SelSet->List ss)))
      (setq ms (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'ModelSpace))
      (foreach obj li
	(setq pl (append pl (list (vlax-get-property obj 'Easting) (vlax-get-property obj 'Northing))))
	)
      (setq poly (vlax-invoke-method ms 'AddLightweightPolyline
		   (vlax-make-variant
		     (vlax-safearray-fill
		       (vlax-make-safearray vlax-vbDouble (cons 0 (- (length pl) 1))) pl))))
      )
    )
  (princ)
  )

(defun sc:SortCogoList (li)
  (vl-sort li (function (lambda (p1 p2) (< (vlax-get-property p1 'Number) (vlax-get-property p2 'Number)))))
  )

(defun sc:SelSet->List (ss / n li obj)
  (setq n 0)
  (setq li '())
  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss n)))
    (setq li (append li (list obj)))
    (setq n (+ n 1))
    )
  li
  )
0 Likes
Message 7 of 12

paulaprediger
Observer
Observer

Hi, i'm trying to use the code, but when i run it, it doenst recognize the points in selection. Can you help me please?

0 Likes
Message 8 of 12

hippe013
Advisor
Advisor

What kind of points are you trying to select? 

 

0 Likes
Message 9 of 12

paulaprediger
Observer
Observer

Sorry, I was using autocad, not civil3d. I was trying common node points. It's not going to work in cad?

0 Likes
Message 10 of 12

hippe013
Advisor
Advisor

Yeah, this particular code is drawing a polyline by the point number property of the Civil 3D Cogo Point. What is it that you are trying to achieve with your regular AutoCAD points? 

 

0 Likes
Message 11 of 12

paulaprediger
Observer
Observer

I have a lot of point and need to create lines conecting them all. Dont mind if its common lines or poly. 

0 Likes
Message 12 of 12

hippe013
Advisor
Advisor

@paulaprediger You should start a new thread with your request. 

0 Likes