Jump to content

Recommended Posts

Posted

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

Posted

You could probably start by googling Lee Mac's dynamic block functions.

Posted

What you are describing is possible. Can you post a dwg containing the blocks and the shape file?

Posted

@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

Posted (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! :D

 

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 by Gotrekk
Posted

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

Posted
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

Posted

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

Posted
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:

Posted
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 :)

Posted

Good stuff :thumbsup:

 

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. :)

Posted (edited)

EDIT: solved

 

thanks a lot :)

Edited by Gotrekk

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...