object selected by lisp in all drawings ..

object selected by lisp in all drawings ..

jaggisingh003
Advocate Advocate
2,783 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,784 Views
24 Replies
Replies (24)
Message 2 of 25

dlanorh
Advisor
Advisor

A sample drawing containing the blocks and saved as AutoCAD 2010 or earlier would help.

 

I am not one of the robots you're looking for

0 Likes
Message 3 of 25

jaggisingh003
Advocate
Advocate

@dlanorh 

plz find the attached drawing.

lisp working exacted in this but in other drawings not getting accurate results.

for select object select 3 pair of text.

ACC1.PNG

 

0 Likes
Message 4 of 25

pbejse
Mentor
Mentor

@jaggisingh003 wrote:

@dlanorh 

plz find the attached drawing.

lisp working exacted in this but in other drawings not getting accurate results.

for select object select 3 pair of text.


Hi @jaggisingh003 , what is considered as the "accurate" results? and what is not ? is it shown on the drawinng you posted?

 

Can you somehow show us please the desired result.

 

 

 

 

Message 5 of 25

jaggisingh003
Advocate
Advocate

ACC1.PNG

This is the format for the correct results as per the codes I want in drawing 4 results is ok but in next drawing values not getting the exact places. 

From selection to right to left or left to right.

 

0 Likes
Message 6 of 25

pbejse
Mentor
Mentor

I dont get this:

 

...
(setq s (entsel "\nSelect exiting ACC1 block"))
...

 

Which block is this one?

Is that the one with 738.50 --- 702.00 ?

Does the block or a block always exists for selection?

 

 

 

0 Likes
Message 7 of 25

jaggisingh003
Advocate
Advocate

There is a block name Acc1 getting their attribute values and paste in the block name SC-Acc.

0 Likes
Message 8 of 25

jaggisingh003
Advocate
Advocate

@pbejse 

yes that block is always there. but with different values.

0 Likes
Message 9 of 25

pbejse
Mentor
Mentor

Is there a reason why your using vanilla lisp  and not ActiveX [ Vlax... ]?

Is this the correct result?

correct.JPG

 

Please confirm if this is right

Message 10 of 25

pbejse
Mentor
Mentor

@pbejse wrote:

Is there a reason why your using vanilla lisp  and not ActiveX [ Vlax... ]?

.....

Please confirm if this is right


Reason I asked that is because you might be using Autocad Mac Version.

Based on your reaction of clicking "like" I will assume that it is correct. and you are using windows version of Autocad.

 

[ code removed: delayed response ]

 

AND please let me kow if you do need a non ActiveX version of the rouinte.

 

HTH

 

Message 11 of 25

jaggisingh003
Advocate
Advocate
yes this is correct but same small correction is their check the attached
image.
Don't have any knowledge about Active-x.
Im new and learning autolisp.
0 Likes
Message 12 of 25

jaggisingh003
Advocate
Advocate

@pbejse Sorry for the late reply

Some issues in internet connections.

I m not using the mac.

see attached images for final results.

I am new to AutoLISP and try to learn and don't have much knowledge of active -x(visual lisp).

 

correct.JPG

0 Likes
Message 13 of 25

pbejse
Mentor
Mentor
Accepted solution

I see, have a look at the picture below:

 

correctomundo.JPG

 

 

See how you had it on your posted code p6 as tag  "loc-1", p2 as tag "ch-1" and so on. Your code is the only reference I have, so it ended up like that.

Anyhoo, I corrected the order now on this code, please tell me how it goes

 

 

(defun C:ACC ( / _insertAtt  data pt1 s2 ss s1 s pt i ent data)
(defun _insertAtt  (pt bn)
 (vlax-invoke (vlax-get (vla-get-ActiveLayout
                 (vla-get-activedocument
                       (vlax-get-acad-object)))'Block)
   					'InsertBlock pt bn  1 1 1 0)
 )
  
(if
 (and
   	(tblsearch "BLOCK" "CO-ACC")
	(tblsearch "BLOCK" "SC-ACC")	
	(setq data nil
	       pt1 (getpoint "\nSelected point for CONDUCTOR DETAILS CO-ACC"))
	(tblsearch "BLOCK" "CO-ACC")
	(setq s2 (vlax-vla-object->ename (_insertAtt pt1 "CO-ACC" )))		
	(setq ss (ssget '((0 . "text")(1  . "*#/#*"))))
	( = (setq i (sslength ss)) 6)
	(setq pt (getpoint "\nSelected point for SCHEMATIC DIAGRAM SC-ACC"))
	(setq s1 (vlax-vla-object->ename (_insertAtt pt "SC-ACC")))
	(setq s (entsel "\nSelect exiting ACC1 block"))
	(eq "Acc1" (Cdr (Assoc 2 (entget (setq s (Car s))))))
   )
	 (progn
		(repeat i
			(setq ent (entget (ssname ss (setq i (1- i)))))
			(setq data (cons
					       (list (cdr (Assoc 10 ent))
						     (cdr (Assoc 1 ent))) data))
		)	   
		(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)))))
				)
	   	(Foreach itm '("TENSION_LENGTH1" "TENSION_LENGTH2"
		 		"MAST_COUNT1" "MAST_COUNT2"
		       			)
		  (setpropertyvalue s1 itm  (getpropertyvalue s itm))
		   )
	   )
 	)
  (princ)
)

 

 

HTH

P.S. You can select the TEXT ivia window selection, does not need to be in any order as long as it lined up the way you had on your sample [ three sets ]

 

 

 

Message 14 of 25

jaggisingh003
Advocate
Advocate

@pbejse thanks for your help.

Sry for that there was some mistake in that picture.

 

 

how to write this without Active-X. Can you show that?

0 Likes
Message 15 of 25

pbejse
Mentor
Mentor

@jaggisingh003 wrote:

@pbejse thanks for your help.

Sry for that there was some mistake in that picture.

...

how to write this without Active-X. Can you show that?


You are welcome @jaggisingh003 , no worries but check the information you provide  to avoid confusion next time.

Its not a big deal, we will just replace the  inserting the blocks and the sorting bit. setup a couple settings to ensure the code will not break , i.e attdia, attreq, the block scale [ uniformyl scaled ], etc...  but no need to do that now. 🙂

 

Message 16 of 25

jaggisingh003
Advocate
Advocate

@pbejse  If you have time can you pls explain this with some easy examples that would very help me. coz I m new and just try to learn autolisp.

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)))))
)
(Foreach itm '("TENSION_LENGTH1" "TENSION_LENGTH2"
"MAST_COUNT1" "MAST_COUNT2"
)
(setpropertyvalue s1 itm (getpropertyvalue s itm))
)
)

0 Likes
Message 17 of 25

pbejse
Mentor
Mentor

Lets start with the easy one

 

(Foreach itm '("TENSION_LENGTH1"
			       "TENSION_LENGTH2"
			       "MAST_COUNT1"
			       "MAST_COUNT2"
			      )
		  (setpropertyvalue s1 itm (getpropertyvalue s itm))
		)

 

The reason we did that so you dont have to  make 8 separate statement. 

 

(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)

 

You also dont need to assign the value to a variable from getpropertyvalue function. and afterwards passing the value to the  setpropertyvalue as argument

 

(setpropertyvalue s1 itm  (getpropertyvalue s itm))

 

But what about the tag names?

By using foreach function, you will be using a temporary variable we named as  itm for every actual name on the given list. 

 

("TENSION_LENGTH1" "TENSION_LENGTH2" "MAST_COUNT1" "MAST_COUNT2" )

 

on the first run itm = "TENSION_LENGTH1"

What is the common thing between this two?

 

(setQ TL1 (getpropertyvalue (car s) "TENSION_LENGTH1"))
(setpropertyvalue s1 "TENSION_LENGTH1" TL1)

 

Yes. "TENSION_LENGTH1", so translating that two statement above into

 

(setpropertyvalue s1 itm  (getpropertyvalue s itm))

 

since itm = "TENSION_LENGTH1"

 

(setpropertyvalue s1 "TENSION_LENGTH1"  (getpropertyvalue s "TENSION_LENGTH1"))

 

the next run will do the same but with the next item on the list --> "TENSION_LENGTH2" and so on...

thus eliminating the need to a fixed named variable for every TAG name.

 

HTH

Message 18 of 25

jaggisingh003
Advocate
Advocate

@pbejse ok.  I got this, 😀.

Thanks for help one more time.

 

and Next ....... 

0 Likes
Message 19 of 25

pbejse
Mentor
Mentor

@jaggisingh003 wrote:

and Next ....... 


PYSCHE.png

 

Whenever i have time buddy... just not today.

 

Message 20 of 25

jaggisingh003
Advocate
Advocate

no issue thanks.. for this  

0 Likes