getpropertyvalue

getpropertyvalue

etilley327KA
Advocate Advocate
2,190 Views
24 Replies
Message 1 of 25

getpropertyvalue

etilley327KA
Advocate
Advocate

When I entsel the block I get the DESC2 value, but when it runs with the ssget, the dump shows it missing. What am I doing wrong?

(defun c:test (/ pointdata ddl i e pointxy)
  (setq pointdata (ssget "_X" '((0 . "INSERT")(8 . "DFORMSHOTS"))))
  (PRINC POINTDATA)
  (repeat (setq ii (sslength pointdata))
  (setq e (ssname pointdata (setq i (1- i))))
  (PRINC e)
  (PRINC (dumpallproperties e))
  (setq ddl (cons (getpropertyvalue e "DESC2") ddl))
  (setq pointxy (cons (list (getpropertyvalue e "Position/X")
                            (getpropertyvalue e "Position/Y")) pointxy))
    (cond
      ((= (strcase ddl) "28") (command "_insert" "r" pointxy "28" "" "" ""))
    ))
)
0 Likes
Accepted solutions (1)
2,191 Views
24 Replies
Replies (24)
Message 2 of 25

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

....

  (repeat (setq ii (sslength pointdata))
  (setq e (ssname pointdata (setq i (1- i))))
....

Could it be a downstream result of the disagreement in variable names?

Kent Cooper, AIA
Message 3 of 25

Sea-Haven
Mentor
Mentor

Can you explain what it is your doing please, the code has a few problems. 

 

Your selecting blocks on a layer, getting "DESC2" is this an attribute value then inserting a block by that name, confusing.

 

Are you using ChatGP its code is not up to scratch.

0 Likes
Message 4 of 25

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

....

  (setq ddl (cons (getpropertyvalue e "DESC2") ddl))
  (setq pointxy (cons (list (getpropertyvalue e "Position/X")
                            (getpropertyvalue e "Position/Y")) pointxy))
    (cond
      ((= (strcase ddl) "28") (command "_insert" "r" pointxy "28" "" "" ""))
    ))
....

That will fail because 'ddl' is not a text string, but a list of text strings.  And that will fail because, similarly, 'pointxy' is not a point [XYZ coordinates list], but a list of points.

Kent Cooper, AIA
Message 5 of 25

etilley327KA
Advocate
Advocate

Couple things ive never tried to do, so I was attempting to piece together snippets from some of my other lisps. I have blocks (insert) that are in a specific layer (dformshots) im trying to extract all the decryption names from each of the selection sets values along with the point its located at. Once thats done, I was going to create a long list of conditions to insert the associated block at the point specified by the description. Usually the numbers for the description match the block im trying to insert.

0 Likes
Message 6 of 25

Sea-Haven
Mentor
Mentor

Ok post a dwg with a couple of blocks, make sure it has a before and after that is labelled. 

 

I dont use get and putproperty as its not supported in my Bricscad.

 

So use the VL functions or the dxf functions

 

(setq ent (car (entsel "\nPick a block ")))

(setq entg (entget ent))
(setq inspt (cdr (assoc 10 entg))) ; insertion point
(setq bname (cdr (assoc 2 entg))) ; block name
(setq lay (cdr (assoc 8 entg))) ; layer name

in ssget
(setq entg (ssname ss (setq i (1- i))))

or

(setq obj (vlax-ename->vla-object (car (entsel "\nPick a block "))))
(setq inspt (vla-get-insertionpoint obj)) ; insertion point
(setq bname (vla-get-name obj)) ; block name not "objectname"
(setq lay (vla-get-layer obj)) ; layer

in a ssget 
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))

 

Just not sure description or an attribute  that you want ?

0 Likes
Message 7 of 25

etilley327KA
Advocate
Advocate

I have this part of another code that works, so I was trying to do something similar, except cycle through each time inserting the desired block according to the description.

(setq s (ssget "_A" '((0 . "INSERT")
(2 . "SRVPNO5")
)))
(repeat (setq g (sslength s))
(setq h (ssname s (setq g (1- g))))
(setq a (cons (getpropertyvalue h "DESC2") a))
)
(repeat (setq ii (sslength fc))
(setq ee (ssname fc (setq ii (1- ii))))

(setq ccl (cons (atof (getpropertyvalue ee "ELEV2")) ccl))
(setq xxl (cons (getpropertyvalue ee "Position/X") xxl))
(setq yyl (cons (getpropertyvalue ee "Position/Y") yyl)))

0 Likes
Message 8 of 25

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

....

(repeat (setq ii (sslength fc))
(setq ee (ssname fc (setq ii (1- ii))))
....


What's 'fc'?

Kent Cooper, AIA
0 Likes
Message 9 of 25

Kent1Cooper
Consultant
Consultant

I'm really not sure I understand, but does this do what you mean?

 

(setq s (ssget "_A" '((0 . "INSERT") (2 . "SRVPNO5"))))
(repeat (setq g (sslength s))
  (setq h (ssname s (setq g (1- g))))
  (setq a (getpropertyvalue h "DESC2"))
  (command "_.insert"
    (cadr ; Block name
      (assoc a
        '(("28" "28") ("41" "R") ("45" "whatever") ("6" "something") ("1" "maybe")
        ;;; ... more as needed ...
        ); list
      ); assoc
    ); cadr
    "_non" (getpropertyvalue h "Position")
    "" "" "" ;;; <-- Scales vary??
  ); command
); repeat

 

But I notice that your "R" Block in the sample drawing is Inserted at a scale of 20, but your "28" Block at a scale of 1.  So some accounting for that difference [and more differences with other Blocks?], or some Block redefinition, would be needed.

Kent Cooper, AIA
0 Likes
Message 10 of 25

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... But I notice that your "R" Block in the sample drawing is Inserted at a scale of 20, but your "28" Block at a scale of 1.  So some accounting for that difference [and more differences with other Blocks?], or some Block redefinition, would be needed.


Like this, building the necessary scale factors into the list of sub-lists?

 

(setq blklst '(("28" "28" 1) ("41" "R" 20) ("45" "whatever" 5) ("6" "something" 100) ("1" "maybe" 2)
  ;;; ... more as needed ...
  ); list
); setq
(setq s (ssget "_A" '((0 . "INSERT") (2 . "SRVPNO5"))))
(repeat (setq g (sslength s))
  (setq h (ssname s (setq g (1- g))))
  (setq a (getpropertyvalue h "DESC2"))
  (command "_.insert"
    (cadr (assoc a blklst)); Block name
    "_non" (getpropertyvalue h "Position"); insertion point
    (caddr (assoc a blklst)) "" 0 ; scales/rotation
  ); command
); repeat

 

 

Kent Cooper, AIA
Message 11 of 25

etilley327KA
Advocate
Advocate

The blocks to insert are preset, I just need the location of the point and what its description is in order to determine which block to insert.

Gather selection set of all (insert) blocks that are in the layer (whateverlayer)

Cycle through each.

  Get the "description name" (DESC2) to determine which block to insert.

  Get the X,Y for that block for the insertion command location.

Then I would use a long list of (cond

   (= (DESC2) 28) (command "_insert" "X,Y" "28" [not sure every insertion block will match the description] ...)

There might be a way easier way to go about this, but I'm unfamiliar with how to go about it.

 

0 Likes
Message 12 of 25

Kent1Cooper
Consultant
Consultant
Accepted solution

@etilley327KA wrote:

... I would use a long list of (cond

   (= (DESC2) 28) (command "_insert" "X,Y" "28" [not sure every insertion block will match the description] ...)

....


Attribute values can only be text strings, so at the least,

(= (DESC2) "28")

That assumes a defined function something like:

(defun DESC2 () (getpropertyvalue YourEntityName "DESC2"))

 

My suggestion goes about it in a different way, using a list (assoc)iating the Attribute's content with a Block name [and a scale in the second version], because it uses a lot less code than spelling out all those (cond)itions, but I think accomplishes the same thing.

Kent Cooper, AIA
0 Likes
Message 13 of 25

etilley327KA
Advocate
Advocate
Cool, ill try and go about it the way you listed. Thank you.
0 Likes
Message 14 of 25

etilley327KA
Advocate
Advocate

Im unfamiliar with this. What is the format to enter variables like this, Im getting an error.

(setq blklst (("28" "28" 1) ("41" "R" 20) ("45" "whatever" 5) ("6" "something" 100) ("1" "maybe" 2))

 

0 Likes
Message 15 of 25

Kent1Cooper
Consultant
Consultant

Sorry about that -- my mistake [which I have corrected in Messages 9 & 10].  The list needs an apostrophe before it:

(setq blklst '(("28" "28" 1) ....

and in Messages 10 and 14, an additional right parenthesis at the end to conclude the (setq) function, and I put the ... more as needed ... inside the list and that additional one.

 

Read about the (list) and (quote) functions to learn more.

Kent Cooper, AIA
0 Likes
Message 16 of 25

etilley327KA
Advocate
Advocate

Im having trouble pulling the DESC2 when I add the layer into the ssget filter. How can I pull only "INSERT" blocks in THE "DFORMSHOTS" layer and get the DESC2 with it?

 
 
0 Likes
Message 17 of 25

Kent1Cooper
Consultant
Consultant

Given the back and forth about small parts, let's see how you put it all together -- post the entire code again for evaluation.

Kent Cooper, AIA
0 Likes
Message 18 of 25

etilley327KA
Advocate
Advocate
(defun c:test (/ blklst s g h a)
(setq blklst '(("28" "28" 1) ("34" "34" 1) ("27" "27" 1)))
(setq s (ssget "_A" '((0 . "INSERT")(8 . "DFORMSHOTS"))))
(repeat (setq g (sslength s))
  (setq h (ssname s (setq g (1- g))))
  (setq a (getpropertyvalue h "DESC2"))
  (PRINC A)
  (command "_.insert" (cadr (assoc a blklst)) "_non" (getpropertyvalue h "Position") (caddr (assoc a blklst)) "" 0)
)
)
0 Likes
Message 19 of 25

etilley327KA
Advocate
Advocate

I think its something with the ssget filter, because regular ssget and selecting the block works. Im not sure what the ssget filter is missing.

0 Likes
Message 20 of 25

Kent1Cooper
Consultant
Consultant

What does it actually return?  How far does it get?  If you temporarily don't localize the variables, but set them all to nil overtly at the beginning, you can check what's in them after you run it.

(defun c:test ();;;;/ blklst s g h a)
  (setq blklst nil s nil g nil h nil a nil);;;; temporarily
  (setq s ....

 

Just for fun [I don't think this should matter if you're in the space where the Block is when you run it], does it make any difference if you use selection mode "_X" instead of "_A"?

Kent Cooper, AIA
0 Likes