Jump to content

Small problem- a little rusty. Just some help with attributes


Bhull1985

Recommended Posts

Hey all, I'm having to modify this routine pretty heavily for a new project that I've been on.

 

I'll be getting past each task as I come to it, and the first one I've came across is this....firstly, there are three tags for the blocks that I am extracting from the .dwg into excel...."Size" "Type" and "Tag".

 

The program I am using creates a "valllist" (values list), and then it shoots each bit of the vallist into excel, so I need these vallist to show the attribute values in a consistent manner.

 

Upon running the subfunction a few times over one drawing, I've noticed that some of the blocks have their attributes in reverse order, creating a fudged vallist. Where the size should be, I'm getting the "tag" in about half of the blocks.

 

I'll post how this vallist is looking, and then the code behind it.

 

(createvallist ss)
(("1623" "L6TM-H2" "02-0.5\"") ("1624" "L6TM-H2" "02-0.5\"") ("1625" "L6TM-H2" "02-0.5\"") ("02-1.5\"" "X1TF-H2" "1601") ("02-0.5\"" "X1TR-H2" "1602") ("02-1\"" "X4S-H2" "1603") ("02-1.5\"" "X1TF-H2" "1606") ("02-0.5\"" "X1TR-H2" "1607") ("02-1\"" "X4S-H2" "1608") ("02-1.5\"" "X1TF-H2" "1611") ("02-0.5\"" "X1TR-H2" "1612") ("02-1\"" "X4S-H2" "1613") ("02-1\"" "U2TR-H2" "1616") ("1615" "L6TN-H2" "02-0.5\"") ("1600" "L6TM-H2" "02-0.5\"") ("1605" "L6TM-H2" "02-0.5\"") ("1610" "L6TM-H2" "02-0.5\"") ("1626" "X1TR-H2" "02-0.5\"") ("1627" "X1TR-H2" "02-0.5\"") ("1628" "X1TR-H2" "02-0.5\"") ("1629" "X1TR-H2" "02-0.5\"") ("1630" "X1TR-H2" "02-0.5\"") ("1631" "X1TR-H2" "02-0.5\"") ("02-0.5\"" "X1TR-H2" "1632") ("02-0.5\"" "X1TR-H2" "1633") ("0.5\"" "X1TR-H2" "1634") ("0.5\"" "X1TR-H2" "1637") ("0.5\"" "L6TM-H2" "1636") ("0.5\"" "L6TM-H2" "1635") ("0.5\"" "X1TR-H2" "1638") ("02-0.5\"" "X5TC-H2" "1639") ("02-0.5\"" "X1TR-H2" "1640") ("" "" "") ("" "" "") ("" "" ""))

 

and here's what creates the vallist, the subfunction

(defun createvallist ( ss / taglist tagrow valrow edata e i)
(setq i -1)
;;FOR OAK GROVE VALVES
(setq TagList '("TYPE" "TAG" "SIZE"))
(repeat (sslength ss)
(setq TagRow nil)
(setq ValRow nil)
(setq Edata (entget (setq e (ssname ss (setq i (1+ i))))))
(while (/= (Dxf 0 Edata) "SEQEND")
(if
(and
(= (Dxf 0 Edata) "ATTRIB")
(member (dxf 2 Edata) TagList)
;;if tag is on list
);and
(progn
(setq TagRow (cons (Dxf 2 Edata) TagRow))
(setq valRow (cons (Dxf 1 Edata) ValRow))
);progn
)
(setq Edata (entget (setq e (entnext e))))
) ;while
(setq vallist (cons valrow vallist))
);repeat 
);defun 

 

Now I've tried code like this, added right under the (setq TagRow...) and (setq ValRow...) portions

 

(progn
(setq TagRow (cons (Dxf 2 Edata) TagRow))
(if (= (car tagrow) (strcase "TAG"))
(reverse tagrow))
(setq valRow (cons (Dxf 1 Edata) ValRow))
(if (= (car tagrow)(strcase "TAG"))
(reverse valrow))
);progn

 

But unfortunately for me the vallist doesn't come out in a consistent manner, despite code that to me should work.

 

Could someone point me in the right direction, getting these attribute values to appear in a consistent fashion no matter the order that the attributes are showing in the blocks/vallist?

 

Thanks in advance!

Link to comment
Share on other sites

How about creating your value list as a list of dotted pairs ie. ("size" . value) ("tag" . value) and etc? I hope that I am understanding you correctly.

 

 

In further thought and testing.

 

Maybe use vlax commands to achieve the desired results.

 

Quick and dirty

 

(setq blk-ref (vlax-ename->vla-object (car (entsel "\nSelect Block:"))))
(setq att-list (vlax-safearray->list (vlax-variant-value (vlax-invoke-method blk-ref 'GetAttributes))))
(setq att-ref (nth 0 att-list))
(setq att-tag (vlax-get-property att-ref 'TagString))
(setq att-string (vlax-get-property att-ref 'TextString))
(setq att-item (cons att-tag att-string))

 

I hope this helps!

 

regards,

 

hippe013

Edited by Hippe013
added code
Link to comment
Share on other sites

Why would you not use the TAG name as the test it would mean you have to write a few lines of code 3 times once for each tag, then they will always be in correct order.

 

Thinking a bit further pick a block create tag list pop DCL pick order then export does not matter how many attributes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...