TemporaryCAD Posted August 2, 2022 Posted August 2, 2022 I'm having issues with dynamicblocks and I'm pretty sure the issue stems from the origin being changed with every block I insert. How do I set this property? ;; Set Dynamic Block Properties - Lee Mac ;; Modifies values of Dynamic Block properties using a supplied association list. ;; blk - [vla] VLA Dynamic Block Reference object ;; lst - [lst] Association list of ((<Property> . <Value>) ... ) ;; Returns: nil (defun setdynprops ( blk lst / itm ) (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst)) (foreach x (vlax-invoke blk 'getdynamicblockproperties) (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst)) (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))) ) ) ) I'm using Lee Mac's code to interface with the dynamicblocks. Using this code, how do I set the "Origin" property? I've tried lists, dotted pairs, safearrays, etc and nothing seems to work. Thank you! Quote
mhupp Posted August 2, 2022 Posted August 2, 2022 I'm guessing this is giving you an error? Needs the vla-object name of the dynamic block not the entity name (vl-load-com) (setq blk (vlax-ename->vla-object (car (entsel "\nSelect Dynamic Block: ")))) (setdynprops blk '((<Property> . <Value>))) Quote
TemporaryCAD Posted August 2, 2022 Author Posted August 2, 2022 Just now, mhupp said: I'm guessing this is giving you an error? Needs the vla-object name of the dynamic block not the entity name (vl-load-com) (setq blk (vlax-ename->vla-object (car (entsel "\nSelect Dynamic Block: ")))) (setdynprops blk '((<Property> . <Value>))) No, I understand this. I am currently using the code to edit dynamic block properties. However, one property is the origin, which I believe is messing with some blocks as I have no control of it's value and it appears to be set incorrectly. All I am looking to do is determine how to edit that origin parameter using that code. Whatever datatype I send it returns an error: (cons "Origin" (vlax-make-safearray vlax-vbdouble '(0 . 0))) (cons "Origin" '(0 . 0)) (cons "Origin" (list 0 0)) (cons "Origin" (cons 0 0)) (cons "Origin" '(0 0)) None of these inputs work. How do I correctly use this code? Thanks! Quote
mhupp Posted August 2, 2022 Posted August 2, 2022 (edited) Wait is origin an attribute or a property of the block like the insertion point? --edit because blocks don't have a property named Origin. that i know of. ;;----------------------------------------------------------------------------;; ;; Dump all methods and properties for selected objects (defun C:VDumpIt (/ ent) (while (setq ent (car (entsel "\nSelect Entity to Dump"))) (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t) ) (textscr) (princ) ) Edited August 2, 2022 by mhupp Quote
mhupp Posted August 2, 2022 Posted August 2, 2022 https://forums.autodesk.com/t5/dynamic-blocks-forum/dynamic-block-origin-0-0/td-p/1753466 Quote Micahsa in reply to: mbuonocore 09-06-2006 06:38 AM The only thing I can think of is to add a base point parameter at 0,0,0 within your db, then line up everything from there. I can't think of any other reason for the block to shift positions on you aside from that. Quote
TemporaryCAD Posted August 2, 2022 Author Posted August 2, 2022 (edited) 19 minutes ago, mhupp said: Wait is origin an attribute or a property of the block like the insertion point? --edit because blocks don't have a property named Origin. that i know of. ;;----------------------------------------------------------------------------;; ;; Dump all methods and properties for selected objects (defun C:VDumpIt (/ ent) (while (setq ent (car (entsel "\nSelect Entity to Dump"))) (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t) ) (textscr) (princ) ) When I use Lee Mac's getdynprops function, I get the following result from the block: (("Stand" . "VisibilityState0") ("Right Arm X" . 74.0225) ("Right Arm Y" . 50.2598) ("Left Arm X" . -56.4576) ("Left Arm Y" . -17.357) ("Stand Height" . 158.5) ("Origin" 0.0 0.0)) I specified all of those except for origin. I assume it's an intrinsic property of a dynamicblock. EDIT: Here's LM's code for reference: ;; Get Dynamic Block Property Value - Lee Mac ;; Returns the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) (defun LM:getdynpropvalue ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value))) (vlax-invoke blk 'getdynamicblockproperties) ) ) Edited August 2, 2022 by TemporaryCAD Quote
mhupp Posted August 2, 2022 Posted August 2, 2022 IDK one of the limiting factors of the version of BricsCAD I have. you can use but not create or edit Dynamic blocks. so I'm a little in the dark on this one. Quote
TemporaryCAD Posted August 8, 2022 Author Posted August 8, 2022 (edited) This topic is very important to me as this is holding up an entire project. Here's an update from some troubleshooting: (setq values (cons "Origin" '(0.0 0.0))) ;input values in an association list (setdynprops (blk values)) ;blk is the block entity reference for the dynamicblock Returns ; error: bad argument type: consp "Origin" and flags this line from Lee Mac's setdynprops code: (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst)) With (car x) being underlined. This is confusing to me as running the (cons (strcase (car x)) (cdr x)) code outside of the lambda function works without the error. I'd greatly appreciate some clarity on this matter. Edit: I think I located the issue: can I create a dotted pair that references a list? i.e. (Origin . (0.0 0.0)) Does this information hold for AutoLisp? Edited August 8, 2022 by TemporaryCAD Quote
Jonathan Handojo Posted August 8, 2022 Posted August 8, 2022 (edited) @TemporaryCADThat function by Lee that you are referencing accepts an association list of values. Therefore it goes as ((<property1> . <value1>) (<property2> . <value2>) .... (<property_n) . <value_n>)). If you were using setdynprops, you will need values as: (setq values (list (cons "Origin" '(0.0 0.0)))) If that still yields an error, try (setq values (list (cons "Origin" (vlax-3d-point 0.0 0.0)))) Edited August 8, 2022 by Jonathan Handojo 1 Quote
TemporaryCAD Posted August 8, 2022 Author Posted August 8, 2022 6 minutes ago, Jonathan Handojo said: @TemporaryCADThat function by Lee that you are referencing accepts an association list of values. Therefore it goes as ((<property1> . <value1>) (<property2> . <value2>) .... (<property_n) . <value_n>)). If you were using setdynprops, you will need values as: (setq values (list (cons "Origin" '(0.0 0.0)))) Thank you! That got through the first layer of issues. I had missed that the association list had to be wrapped in a list. Now, I've encountered a different issue. I am trying to set a point that refers to a single property name. This is causing issues, as I am now seeing this error: lisp value has no coercion to VARIANT with this type: (0.0 0.0) In this code: (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))) For the other points I've set they've had separate x and y coord properties, but this one wants both values at once. When I use Lee Mac's getdynprops code, it returns a list of reals. I had hoped returning that would work, but now it is throwing the above error. Please advise! Quote
Jonathan Handojo Posted August 8, 2022 Posted August 8, 2022 (edited) @TemporaryCAD Correct. So then it seems you need to convert the list input into a 3D point that is ActiveX compatible. This is done so using vlax-3D-Point. You can easily do it using (vlax-3D-point 0.0 0.0). Or if you are passing the list that's returned by getdynprops, you may choose to convert it like this: (setdynprops <block_1> (mapcar '(lambda (x / v) (cons (car x) (if (and (listp (setq v (cdr x))) (vl-every 'numberp v)) (vlax-3d-point v) v ) ) ) (getdynprops <block_2>) ) ) Edited August 8, 2022 by Jonathan Handojo 2 Quote
TemporaryCAD Posted August 8, 2022 Author Posted August 8, 2022 11 minutes ago, Jonathan Handojo said: @TemporaryCAD Correct. So then it seems you need to convert the list input into a 3D point that is ActiveX compatible. This is done so using vlax-3D-Point. You can easily do it using (vlax-3D-point 0.0 0.0). Or if you are passing the list that's returned by getdynprops, you may choose to convert it like this: (setdynprops (mapcar '(lambda (x / v) (cons (car x) (if (and (listp (setq v (cdr x))) (vl-every 'numberp v)) (vlax-3d-point v) v ) ) ) (getdynprops <your_block>) ) ) Thank you for the excellent advice. I wrote a quick function to keep the origin at (0,0): (defun resetorigin (blk) (foreach x (vlax-invoke blk 'getdynamicblockproperties) (if (eq (strcase (vla-get-propertyname x)) "ORIGIN") (vla-put-value x (vlax-3d-point 0.0 0.0)) ) ) ) However, I am getting an "Automation Error. Invalid input" - I've never encountered this before. Do you have any idea what might be causing this? Quote
Jonathan Handojo Posted August 8, 2022 Posted August 8, 2022 Hmm... that's a first for me as well. Do you have the block in question? Maybe might be worth seeing what's wrong with it and if I can debug some issues. Perhaps others might have heard of this issue. Quote
TemporaryCAD Posted August 8, 2022 Author Posted August 8, 2022 11 minutes ago, Jonathan Handojo said: Hmm... that's a first for me as well. Do you have the block in question? Maybe might be worth seeing what's wrong with it and if I can debug some issues. Perhaps others might have heard of this issue. Unfortunately I cannot share the blocks I am working with, but you should be able to use any dynamicblock for testing (I believe they all share an origin property). I am wondering if I am selecting blocks incorrectly: I am using (resetorigin(vlax-ename->vla-object(car(entsel)))) to quickly check the code and it does throw an error: (vla-get-propertyname (getdynprops(vlax-ename->vla-object(car(entsel))))) Select object: ; error: bad argument type: VLA-OBJECT (("Distance1" . 15.0497) ("Origin" 0.0 10.0)) However, the code in question works differently as it uses entlast to select the inserted entity, so I'm not certain it ends up mattering. Quote
BIGAL Posted August 9, 2022 Posted August 9, 2022 "I believe they all share an origin property" Could not find this in blocks I looked at. Maybe deeper somewhere not shown. Quote
TemporaryCAD Posted August 9, 2022 Author Posted August 9, 2022 (edited) On 8/8/2022 at 7:44 PM, BIGAL said: "I believe they all share an origin property" Could not find this in blocks I looked at. Maybe deeper somewhere not shown. Interesting. Maybe some setting, perhaps at a organization level, is generating the origin parameter. I believe it is causing issues by altering other parameters when it is inadvertently changed. I've attached a simple dynamic square with two parameters, including the mysterious origin. See above for the code I am using to attempt to edit the origin. I really appreciate all the help - if this is the root cause of my issues it will resolve a multiple week roadblock. Edited August 10, 2022 by TemporaryCAD Quote
TemporaryCAD Posted August 9, 2022 Author Posted August 9, 2022 27 minutes ago, ronjonp said: Take a look: Thank you for the reply. First, are you saying the "origin" property is read only? Would it be possible to toggle that with a :vlax-false in code, or is that editable in the block editor? Second, I am using VScode as that will be the future platform for autolisp. Is there a way to see information like that with on that platform? Quote
ronjonp Posted August 9, 2022 Posted August 9, 2022 (edited) 2 hours ago, TemporaryCAD said: Thank you for the reply. First, are you saying the "origin" property is read only? Would it be possible to toggle that with a :vlax-false in code, or is that editable in the block editor? Second, I am using VScode as that will be the future platform for autolisp. Is there a way to see information like that with on that platform? AFAIK it cannot be changed. As for how to get that info in VSCODE, I'd have to defer to someone else as I've not moved into the 'future' yet :). Edited August 9, 2022 by ronjonp Quote
Lee Mac Posted August 9, 2022 Posted August 9, 2022 As Ron has correctly indicated, the Dynamic Block Property objects with property name 'Origin' are always read-only and cannot (and should not) be modified - such properties typically accompany other dynamic property objects corresponding to parameters whose values can be modified. The ReadOnly property of a Dynamic Block Property object is itself read-only, as indicated by the property list returned by vlax-dump-object: ; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface ; Property values: ; AllowedValues (RO) = nil ; Description (RO) = "" ; PropertyName (RO) = "Origin" ; ReadOnly (RO) = -1 ; show (RO) = 0 ; UnitsType (RO) = 0 ; Value = (0.0 0.0) Quote
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.