Lisp to add multiple nubered line types.

Lisp to add multiple nubered line types.

arpansark0544TCX
Advocate Advocate
492 Views
4 Replies
Message 1 of 5

Lisp to add multiple nubered line types.

arpansark0544TCX
Advocate
Advocate

Hello everyone hope you are doing good.

In pursuit to solve my complex electrical conducting problem, I need help in Lisp which can add multiple line types. 

I am attaching DWG and some photos of what should be the result. Along with my Custom.Lin file.

Thank you.

 

arpansark0544TCX_0-1704698161359.pngarpansark0544TCX_1-1704698177821.png

arpansark0544TCX_2-1704698189592.png

 

0 Likes
Accepted solutions (1)
493 Views
4 Replies
Replies (4)
Message 2 of 5

vladimir_michl
Advisor
Advisor

Do you mean the existing numbers should be added to auto-create a new linetype? I have no solution for that but the utility LtFly can help to create new linetypes on-the-fly, just by specifying the label text. See:

https://www.cadforum.cz/en/create-autocad-complex-linetypes-on-the-fly-tip7147

 

Vladimir Michl, www.arkance-systems.cz  -  www.cadforum.cz

 

Message 3 of 5

hak_vz
Advisor
Advisor
Accepted solution

@arpansark0544TCX 

Modified from solution to your previous request. Don't have time to modify code to work with lines and polylines so only use lines. You didn't have to open new post.

 

(defun c:add_C_lines ( / *error* duplicates ss e ent i ptlist p ovl old_expert dup)

	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(setvar 'cmdecho 1)
		(setvar 'expert old_expert)
		(vla-endundomark adoc)
		(princ)
	)
	(defun duplicates ( lst )
		(if lst
			(if (member (car lst) (cdr lst))
				(cons (car lst) (duplicates (vl-remove (car lst) (cdr lst))))
				(duplicates (vl-remove (car lst) (cdr lst)))
			)
		)
	)
	(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(vla-endundomark adoc)
	(vla-startundomark adoc)	
	(setq old_expert (getvar 'expert))
	(setq ss (ssget "X" '((0 . "LINE")(8 . "EE-POWER CIRCUIT"))) i -1)
	(setvar 'cmdecho 0)
	(while (< (setq i (1+ i)) (sslength ss))
		(setq 
			ent (entget (ssname ss i))
			a (cdr (assoc 10 ent))
			b (cdr (assoc 11 ent))
			ptlist (cons (mapcar 'fix (mapcar '* '(0.5 0.5)(mapcar '+ a b))) ptlist)
		)
	)
	(foreach pt (duplicates ptlist)
		(setq ss (ssget "_C" (mapcar '+ '(15 15) pt) (mapcar '+ '(-15 -15) pt) '((0 . "LINE"))))
		(setq i -1 cnt 0)
		(while (< (setq i (1+ i)) (sslength ss))
			(setq cnt (+ cnt (atoi(substr (cdr (assoc 6 (entget(ssname ss i))))2))))
			(if (>= i 1)(entdel (ssname ss i)))
		)
		(setq e (ssname ss 0))
		(command "_.linetype" "load" (strcat "C" (itoa cnt)) "acad.lin" "")
		(command "_.chprop" e "" "LTYPE" (strcat "C" (itoa cnt)) "")
	)
	
	(setvar 'expert old_expert)
	(setvar 'cmdecho 0)
	(vla-endundomark adoc)
	(princ "\nDone!")
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 5

arpansark0544TCX
Advocate
Advocate

Is there any modification needed in the code to do for other Letters?

My final design with the help of lisp. The complex network of conduits are reduce to some numbered line in different layers and line types.

arpansark0544TCX_0-1704790972208.png

 

0 Likes
Message 5 of 5

hak_vz
Advisor
Advisor

@arpansark0544TCX 

Later today, if I find some time, I'll make adjustments so that you can select other base layer and destination layer, and to define used linetype group i.e. C D E or whatever. You can also write all your other requests so we can add it to final code.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.