regapp variable ID

regapp variable ID

wian.meier
Enthusiast Enthusiast
935 Views
9 Replies
Message 1 of 10

regapp variable ID

wian.meier
Enthusiast
Enthusiast

Good day all,

 

I'm trying to create a new regapp, with a variable ID (based on the selected polyline dxf code 5 handle) and I can't seem to get it to work.

 

Where am I getting this wrong?

 

(setq CableID (cdr (assoc 5 Cable)));DXF code 5 from selected Cable
(regapp CableID);The app should be registered as the CableID
(setq LastFiber (entget (car (list (entlast)))))
(setq FibreData (list (list -3 (list CableID (cons 1000 CableID) (cons 1000 Fiber) ))))
(setq newlist (append LastFiber FibreData))
(entmod newlist)

 

0 Likes
936 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant

>>" and I can't seem to get it to work."

Where is the problem, what is the feedback from acad?

 

But it works,

not useful in my eyes, but works without a problem (if FIBER is defined)

 

 

Sebastian

0 Likes
Message 3 of 10

wian.meier
Enthusiast
Enthusiast

When trying to retrieve the the xdata of the last line created it gives me this error: bad function: "17A9B" (17A9B is the last drawn line's handle which should be the app name)

 

This is where it fails:

(setq elist (entget (car (list (entlast))) (CableID)))

 

The use of this piece of code is to associate all the fibres to the main cable. It allows me to create a selection set for splicing  

0 Likes
Message 4 of 10

cadffm
Consultant
Consultant

This line wasn't part of your previous post..

 

okay, simple Lisp basics, nothing to do with xdata, let's go:

 

 

nonsens
(setq LastFiber (entget (car (list (entlast)))))
...
(setq LastFiber (entget (entlast)))

 

nonsens and mistake
(setq elist (entget (car (list (entlast))) (CableID)))
...
(setq elist (entget (entlast) (list -3 (list CableID))))

 

?

 

Sebastian

0 Likes
Message 5 of 10

wian.meier
Enthusiast
Enthusiast

When trying this I get this error: not a string in the list: -3

0 Likes
Message 6 of 10

cadffm
Consultant
Consultant

Which line? We can not see what you talk about when you doesn't write it to your answer 🙂

 

I guess, the last line, because i made a mistake:

Nonsens and mistake
(setq elist (entget (car (list (entlast))) (CableID)))
...EDIT...
(setq elist (entget (entlast) (list CableID)))

 

 

?

Sebastian

0 Likes
Message 7 of 10

ronjonp
Mentor
Mentor

Just a nit-picky thing but handles should be stored under 1005 code.

0 Likes
Message 8 of 10

john.uhden
Mentor
Mentor

If CableID is used as the regapp name, then it is redundant to include it in the code 1000.  It serves no purpose other than bloating the drawing and perhaps slowing down your extraction code.

John F. Uhden

0 Likes
Message 9 of 10

john.uhden
Mentor
Mentor

You are treating (CableId) as if it were a function, but CableID is a string.  You must use (list CableID).

John F. Uhden

0 Likes
Message 10 of 10

wian.meier
Enthusiast
Enthusiast

Here is the LISP that I'm writing.

 

It goes through every cable in the drawing and it splits them according to the amount of fibres it has. Each fibre is then associated to the main cable.

 

To achieve this a new app is created for each cable using their DXF code 5 data. From there it gets linked to the Fibre by means of xdata, the data (Main cable handle and fibre number) is then stored in code 1000.

 

The whole reason for this is to splice different fibres to different cables, here is an example of it:

We have 2 cables eg: A & B.

 

Cable A consists of 4 fibres and cable B has 12

 

I'm trying to write a lisp that will then ask you, which fibre of cable A would you like to splice cable B?

To do this the fibres needs to be linked to their parent cable.

 

Does my code make sense?

(defun c:cableconv (/ n LastFiber FibreData newlayer color newlist ltype CableID Fiber Cable ctr len rep LayerType cableSel ptlist ss )
	(setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "2F Aerial,4F Aerial,12F Aerial,18F Aerial,36F Aerial,48F Aerial,72F Aerial,96F Aerial,144F Aerial,12F,24F,36F,48F,72F,96F,144F"))))
	(setq ctr 0);Sets list counter
	(setq len (sslength ss));Sets list length
	(while (/= ctr len)
		(setq cableSel (ssname ss ctr));Selects entity name
		(setq Cable (entget cableSel))
			(cond ;This will be used to determine the repeat length later
				((= "144F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "144"))
				((= "96F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "96"))
				((= "72F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "72"))
				((= "48F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "48"))
				((= "36F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "36"))
				((= "24F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "24"))
				((= "12F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "12"))
				((= "144F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "144"))
				((= "96F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "96"))
				((= "72F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "72"))
				((= "48F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "48"))
				((= "36F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "36"))
				((= "18F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "18"))
				((= "12F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "12"))
				((= "4F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "4"))
				((= "2F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "2"))
			(t (alert "error at Condtions"));Error trap                   
			);cond
				(and 
					(foreach itm
						(setq ptlist 
							(mapcar 'cdr
								(vl-remove-if-not '(lambda	(x) (= (car x) 10)) Cable)
							)
						);setq
				(print itm)
					);foreach
				);and
			(setq CableID (cdr (assoc 5 Cable))); This sets the Parent cable ID
			(setq n 1)
			(setq rep (atoi LayerType))
			(repeat rep 
			(setq Fiber (strcat "F" (itoa (- (atoi(rtos (1+ n) 2 0)) 1))))
				(setq newlayer (strcat Fiber " ")); Uses text to set variable
				(setq ltype "continuous"); linetype
				(setq color "red"); color
				(command "layer" "m" newlayer "lt" ltype "" "c" color "" "")
			(entmakex
				(append
				(list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
						;(cons 8 newlayer);Layer
						(cons 90 (length ptlist)) '(70 . 0))

				(mapcar (function (lambda (p) (cons 10 p))) ptlist)
				);append
			)
			(regapp CableID)
			(setq LastFiber (entget (car (list (entlast)))))
			(setq FibreData (list (list -3 (list CableID (cons 1000 CableID) (cons 1000 Fiber) ))))
			(setq newlist (append LastFiber FibreData))
			(entmod newlist)
			;(setq elist (entget (entlast) (list CableID))) <- Was a test to see if the APP name registered
			(setq n (1+ n))
			)					
		(setq ctr (1+ ctr))
	)
(alert "this worked")
(princ)
)
0 Likes