Gotrekk Posted November 21, 2015 Share Posted November 21, 2015 Hi there, I have many different blocks with different attributes and custom properties (rotation angle, position 1 X, position 1 Y, and so on). All of them have a perfect correspondence between attributes names and custom properties names. For example, if i have a block with custom properties "rotation_head" and "position_head" i will have two attributes called "rotation_head" and "position_head". I'd need a lisp with two functions cycling through all the selected different blocks; one of the function would: - for each selected block, read the attributes and set the custom properties while the other would: - for each selected block, read the custom properties and set the attributes. Do you think something like this would be possible? The reason behind this kind of request is because i need to import and export shapefiles to autocad map and i need to set blocks custom properties using shapefiles table.a Thanks in advance for any ideas/tips Regards GTK Quote Link to comment Share on other sites More sharing options...
iconeo Posted November 21, 2015 Share Posted November 21, 2015 You could probably start by googling Lee Mac's dynamic block functions. Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted November 24, 2015 Share Posted November 24, 2015 What you are describing is possible. Can you post a dwg containing the blocks and the shape file? Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 25, 2015 Author Share Posted November 25, 2015 @Hippe013, you can find both the dwg and the shp attached. @iconeo, i found the routines you're referring to, but i suppose i'm too newbie to lisp to be able to do it on my own lisp_example.zip Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 25, 2015 Author Share Posted November 25, 2015 (edited) slowly... slowly... getting there, using Mac Lee function i got to this point: (defun c:testx1 ( / ent ) (if (setq ent (car (entsel "\nSelect Attributed Block: "))) (princ (LM:setdynpropvalue (vlax-ename->vla-object ent) "value_a" ; custom_property (atof (LM:GetAttributeValue (vlax-ename->vla-object ent) "value_a" ) ) ) ) ) (princ) ) this way i'm able to set custom property "value_a" with value of attribute "value_a" on the selected block! next step is... how do i select many different blocks and run the same function on them? i tried: (defun c:a1(/ ss i obj j k mt) (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (princ(LM:GetAttributeValue(obj) "Matricola")) ) ) (princ) )(vl-load-com) but fails ... any hints? Edited November 25, 2015 by Gotrekk Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted November 25, 2015 Share Posted November 25, 2015 I haven't looked into your code too much. The first that would come to mind is how you are counting your ss index. maybe something like this... (setq cnt 0) (repeat (sslength ss) (setq obj (vlax-ename->vla-object (ssname ss cnt))) (princ (LM:GetAttributeValue obj "Matricola")) (setq cnt (+ cnt 1)) ) Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 26, 2015 Author Share Posted November 26, 2015 I haven't looked into your code too much. The first that would come to mind is how you are counting your ss index. maybe something like this... (setq cnt 0) (repeat (sslength ss) (setq obj (vlax-ename->vla-object (ssname ss cnt))) (princ (LM:GetAttributeValue obj "Matricola")) (setq cnt (+ cnt 1)) ) i tried your solution, i don't get error but nothing get printed... i even tried (princ cnt) inside the repeat... but no output at all Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 26, 2015 Share Posted November 26, 2015 It looks like you are using the Vanilla AutoLISP version of my Get Attributes function, therefore, you should supply this function with a block reference entity name as opposed to a vla-object. Here is a simple example: (defun c:a1 ( / ent idx sel val ) (if (setq sel (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq idx (sslength sel)) (setq ent (ssname sel (setq idx (1- idx)))) (if (setq val (LM:getattributevalue ent "Matricola")) (princ (strcat "\n" val)) (princ (strcat "\nAttribute tag \"Matricola\" not found in block " (cdr (assoc 2 (entget ent))))) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 26, 2015 Author Share Posted November 26, 2015 It looks like you are using the Vanilla AutoLISP version of my Get Attributes function, therefore, you should supply this function with a block reference entity name as opposed to a vla-object. Here is a simple example: (defun c:a1 ( / ent idx sel val ) (if (setq sel (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq idx (sslength sel)) (setq ent (ssname sel (setq idx (1- idx)))) (if (setq val (LM:getattributevalue ent "Matricola")) (princ (strcat "\n" val)) (princ (strcat "\nAttribute tag \"Matricola\" not found in block " (cdr (assoc 2 (entget ent))))) ) ) ) (princ) ) first of all, thank for your help! using your function i still get: ; error: bad argument type: VLA-OBJECT Command: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 26, 2015 Share Posted November 26, 2015 What version of my LM:getattributevalue function are you using? Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 26, 2015 Author Share Posted November 26, 2015 What version of my LM:getattributevalue function are you using? (defun LM:GetAttributeValue ( blk tag ) ;; © Lee Mac 2010 (vl-some (function (lambda ( attrib ) (if (eq tag (vla-get-Tagstring attrib)) (vla-get-TextString attrib) ) ) ) (vlax-invoke blk 'GetAttributes) ) ) ok.. got it... i switched to: ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:getattributevalue ( blk tag / enx ) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (cdr (assoc 1 enx)) (LM:getattributevalue blk tag) ) ) ) and it's now working Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 26, 2015 Share Posted November 26, 2015 Good stuff You may refer to my site to obtain the latest versions of the functions; I renamed the Visual LISP functions to avoid this very problem. Quote Link to comment Share on other sites More sharing options...
Gotrekk Posted November 26, 2015 Author Share Posted November 26, 2015 (edited) EDIT: solved thanks a lot Edited November 26, 2015 by Gotrekk Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.