object selected by lisp in all drawings ..

object selected by lisp in all drawings ..

jaggisingh003
Advocate Advocate
2,793 Views
24 Replies
Message 1 of 25

object selected by lisp in all drawings ..

jaggisingh003
Advocate
Advocate

PLZ HELP me in this, Here a code I m working for selection of specific text to transfer their values to insert attribute blocks placed at different points by this code In Different drawing variables change and values mismatched..

 

Plz help..

 

(defun C:ACC (/ ss e pt pt1 i p1 p2 p3 p4 p5 p6)
(setq pt1 (getpoint "\nSelected point for CONDUCTOR DETAILS CO-ACC"))
(command "_.insert" "CO-ACC" "_S" 1 "_R" 0 "_NONE" pt1)
(setq s2 (entlast))
(setq ss (ssget '((0 . "text"))))
(setq i 0)
(repeat (sslength ss)
(setq e (ssname ss i))
(setq p1 (cdr (assoc 1 (entget e)))))
(setq ss (ssdel e ss))
(setq e (ssname ss i))
(setq p2 (cdr (assoc 1 (entget e))))
(setq ss (ssdel e ss))
(setq e (ssname ss i))
(setq p3 (cdr (assoc 1 (entget e))))
(setq ss (ssdel e ss))
(setq e (ssname ss i))
(setq p4 (cdr (assoc 1 (entget e))))
(setq ss (ssdel e ss))
(setq e (ssname ss i))
(setq p5 (cdr (assoc 1 (entget e))))
(setq ss (ssdel e ss))
(setq e (ssname ss i))
(setq p6 (cdr (assoc 1 (entget e))))
(setpropertyvalue s2 "ch-1" p2)
(setpropertyvalue s2 "loc-1" p6)
(setpropertyvalue s2 "ch-3" p1)
(setpropertyvalue s2 "loc-3" p4)
(setq pt (getpoint "\nSelected point for SCHEMATIC DIAGRAM SC-ACC"))
(command "_.insert" "SC-ACC" "_S" 1 "_R" 0 "_NONE" pt)
(setq s1 (entlast))
(setq s (entsel "\nSelect exiting ACC1 block" )); Select exiting ACC1 block
(setQ TL1 (getpropertyvalue (car s) "TENSION_LENGTH1"))
(setQ TL2 (getpropertyvalue (car s) "TENSION_LENGTH2"))
(setQ MC1 (getpropertyvalue (car s) "MAST_COUNT1"))
(setQ MC2 (getpropertyvalue (car s) "MAST_COUNT2"))
(setpropertyvalue s1 "TENSION_LENGTH1" TL1)
(setpropertyvalue s1 "TENSION_LENGTH2" TL2)
(setpropertyvalue s1 "MAST_COUNT1" MC1)
(setpropertyvalue s1 "MAST_COUNT2" MC2)
(setpropertyvalue s1 "ch-2" p3)
(setpropertyvalue s1 "loc-2" p5)
)

0 Likes
Accepted solutions (1)
2,794 Views
24 Replies
Replies (24)
Message 21 of 25

jaggisingh003
Advocate
Advocate

@pbejse  If you have some time please explain this remain code .. that would be a great help.

(mapcar '(lambda (c d)
(setpropertyvalue
(if (member c '("LOC-2" "CH-2"))
s1 s2) c d) d )
'("ch-1" "loc-1" "CH-2" "LOC-2" "ch-3" "loc-3" )
(mapcar 'cadr
(vl-sort data '(lambda (a b)
(< (caar a)(caar b)))))
)

0 Likes
Message 22 of 25

jaggisingh003
Advocate
Advocate

@pbejse

 If you have some time please explain this remain code .. that would be a great help.

thanks in advance

(mapcar '(lambda (c d)
(setpropertyvalue
(if (member c '("LOC-2" "CH-2"))
s1 s2) c d) d )
'("ch-1" "loc-1" "CH-2" "LOC-2" "ch-3" "loc-3" )
(mapcar 'cadr
(vl-sort data '(lambda (a b)
(< (caar a)(caar b)))))
)

0 Likes
Message 23 of 25

pbejse
Mentor
Mentor

@jaggisingh003 wrote:

@pbejse

 If you have some time please explain this remain code .. that would be a great help.


Yes I did say if i have time didnt I? is your question about mapcar/lambda in general?  I'm not going to spend time explaining all that.

 

As for the code you posted

 

(vl-sort data
	 '(lambda (a b)
	    (< (caar a) (caar b))
	  )
)

((-9793.44 Y Z) "160/223.50") ;<--- a
((-9726.75 Y Z) "160/291.00") ;<--- b
((-9659.65 Y Z) "160/354.00") 
((-9659.65 Y Z) "160/6") 
((-9657.22 Y Z) "160/5") 
((-9790.85 Y Z) "160/4") 


;;	variable "a" value is
((-9793.44 Y Z) "160/223.50")
(car a)
	(-9793.44 Y Z)
(car (car a))
	-9793.44

;;	variable "b" value is
((-9726.75 Y Z) "160/291.00")
(car b)
	(-9726.7	5 Y Z)
(car (car b))		;<-- first item or the first item 
	-9726.75

(< -9793.44 -9726.75)	;<-- sort by this item

or simply
(car (Car x)) = (caar x);<--- Each a represents a call to car and each d represents a call to cdr

 

The result is a sorted list based on X coordinate value.

((-9793.44 Y Z) "160/223.50")  <--- lowest X value
((-9790.85 Y Z) "160/4")
((-9726.75 Y Z) "160/291.00")
((-9724.72 Y Z) "160/5")
((-9659.65 Y Z) "160/354.00")
((-9657.22 Y Z) "160/6")  <--- highest X value

 

Not really sure [ so dont quote me on this ], but I think vl-sort is using "insertion sort" algorithm,  it is slow compared to a well written sorting algorithm using say a while function.

 

About Point Lists (AutoLISP)  <-- read this

As for this line

 

(mapcar 'cadr
	[ the data above ]
		)

 

Will give you a list of every 2nd item ( cadr ) of a given list

("160/223.50" "160/4" "160/291.00" "160/5" "160/354.00""160/6")

 

Mapcar always returns a list.

 

And that is all the time I have for today, its Sunday after all.

 

HTH

 

Message 24 of 25

Sea-Haven
Mentor
Mentor

Pbejse, converted fortran Bubblesort to lisp like 30 years ago no idea where code is now. 

0 Likes
Message 25 of 25

pbejse
Mentor
Mentor

@Sea-Haven wrote:

Pbejse, converted fortran Bubblesort to lisp like 30 years ago no idea where code is now. 


I for one would want to see that code,  sometimes a code written 10 years ago feels likes yesterday and then I wonder where I saved the file. 😄

 

 

 

0 Likes