Author Topic: setting dynamic properties  (Read 3210 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 725
setting dynamic properties
« on: April 02, 2022, 02:04:29 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:K    (   / p1 p2 ang-12 dst-12 ins-obj model-space)
  2.    (setq p1 (getpoint     "\nfirst point : "  ) )
  3.    (setq p2 (getpoint p1  "\nsecond point : " ) )
  4.  
  5.    (setq dst-12  (distance p1 p2)   ang-12 (angle p1 p2) )
  6.  
  7.  
  8.    (setq ins-obj (vla-InsertBlock model-space (vlax-3d-point p1 ) "DB-LINE-DIM-X" 1.0 1.0 1.0 ang-12 ) )
  9.  
  10.    (LM:SETDYNPROPS
  11.       ins-obj
  12.       (list   (cons "distance-p1-p2" dst-12)
  13.             (cons "text-position X" 1.0 )
  14.       )
  15.    )
  16. )
  17.  

I am trying tu put the "text-position X" along the direction p1 p2, and at the distance 1.0 from p1
but the result is strange. . . I do not understand . . .

if instead I assign the value 1.0 to the "text-distance X" property in the properties panel, everything is fine . . .

. . . but via lisp, it's not good.

have anyone any ideas?

Make the distance between p1 and p2 greater than 1.0
... make it 4 or 5 or more ...... just to understand better ...

« Last Edit: April 02, 2022, 02:35:37 AM by domenicomaria »

ribarm

  • Gator
  • Posts: 3306
  • Marko Ribar, architect
Re: setting dynamic properties
« Reply #1 on: April 02, 2022, 02:45:19 AM »


Not sure, but according to your request, probably you should change this :

(cons "distance-p1-p2" dst-12)

to :

(cons "distance-p1-p2" 1.0)



I could be wrong here...
« Last Edit: April 02, 2022, 03:00:08 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #2 on: April 02, 2022, 02:58:35 AM »


Not sure, but according to your request, probably you should change this :

(cons "distance-p1-p2" dst-12)

to :

(cons "distance-p1-p2" 1.0)



I could be wrong here...

No Ribarm !
I use (cons "distance-p1-p2" dst-12)
to put p2 in the right position ...
...
while I use (cons "text-position X" 1.0 )
to put the text at the distance of 1.0 from p1
...
try to play with this dynamic block . . .




ribarm

  • Gator
  • Posts: 3306
  • Marko Ribar, architect
Re: setting dynamic properties
« Reply #3 on: April 02, 2022, 03:12:44 AM »
There are plenty ways to achieve what you ask...
Just to mention some approaches :

look at [ (setq pt (polar p1 ang dist)) ] (2D)
look at [ (setq pt (mapcar (function +) p1 (mapcar (function *) (mapcar (function /) (mapcar (function -) p2 p1) (list (distance p1 p2) (distance p1 p2) (distance p1 p2))) (list 1.0 1.0 1.0)))) ] (3D) [ 1.0 - value of strength of vector - here coincidently it corresponds to unit vector ]
« Last Edit: April 02, 2022, 03:32:56 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #4 on: April 02, 2022, 07:26:43 AM »
@ribarm

i think the problem is related to dynamic blocks ... i don't know what ...
...
if you don't play with the attached dynamic block, you cannot understand

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: setting dynamic properties
« Reply #5 on: April 02, 2022, 07:56:33 AM »
Add the following below the insertion codes of the dynamic block to set the parameter accordingly.
Code - Auto/Visual Lisp: [Select]
  1.     '(lambda (x)
  2.        (and (= (vla-get-propertyname x) "distance-p1-p2")
  3.             (or (vlax-put x 'Value dst-12) t)
  4.        )
  5.      )
  6.     (vlax-invoke ins-obj 'getdynamicBlockproperties)
  7.   )
  8.  

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #6 on: April 02, 2022, 08:41:56 AM »
Add the following below the insertion codes of the dynamic block to set the parameter accordingly.
Code - Auto/Visual Lisp: [Select]
  1.     '(lambda (x)
  2.        (and (= (vla-get-propertyname x) "distance-p1-p2")
  3.             (or (vlax-put x 'Value dst-12) t)
  4.        )
  5.      )
  6.     (vlax-invoke ins-obj 'getdynamicBlockproperties)
  7.   )
  8.  

Thank you, Tharwat

It works well !

You hit the problem straight away !

But help me to understand,
why it is not possible to use LM:SETDYNPROPS
to set the value of more the one properties, at the same time,
without finding this kind of problem  ...

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: setting dynamic properties
« Reply #7 on: April 02, 2022, 08:54:37 AM »
Thank you, Tharwat
You're welcome.

But help me to understand,
why it is not possible to use LM:SETDYNPROPS
to set the value of more the one properties, at the same time,
without finding this kind of problem  ...

I did not review the function but you may need to read about the supplied arguments then you can find where the problem is very easily if that function is the one you need to use here or not.

I recommend you to always try to write your own functions ( if you can ) to have full control over your programs otherwise you might keep on struggling from time to time with other's codes.

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #8 on: April 02, 2022, 09:08:18 AM »
@Tharwat
Quote
I recommend you to always try to write your own functions ( if you can ) to have full control over your programs otherwise you might keep on struggling from time to time with other's codes.

Yes. You are absolutely right,
but LM:SETDYNPROPS is by Lee Mac !
...
and anyway in my original code, what didn't work
was not the assignment of the value to "distance-p1-p2"
but it was the assignment of the value to "text-position X" ...

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #9 on: April 02, 2022, 09:19:55 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:K    (   / ang-12 dst-12 dyn-blk-props ins-obj model-space p1 p2 )
  2.    (setq p1 (getpoint     "\nfirst point : "  ) )
  3.    (setq p2 (getpoint p1  "\nsecond point : " ) )
  4.  
  5.    (setq dst-12  (distance p1 p2)   ang-12 (angle p1 p2) )
  6.  
  7.  
  8.    (setq ins-obj (vla-InsertBlock model-space (vlax-3d-point p1 ) "DB-LINE-DIM-X" 1.0 1.0 1.0 ang-12 ) )
  9.  
  10.  
  11.    (setq dyn-blk-props (vlax-invoke ins-obj 'getdynamicBlockproperties) )
  12.    
  13.    ;;;   (vla-get-propertyname (nth 0 dyn-blk-props) )   ;   "text-position X"  
  14.    ;;;   (vla-get-propertyname (nth 2 dyn-blk-props) )   ;   "distance-p1-p2"  
  15.  
  16.    (vlax-put (nth 2 dyn-blk-props) 'Value dst-12)
  17.    (vlax-put (nth 0 dyn-blk-props) 'Value 1.23 )
  18. )
  19.  

the above code works well and is very simple and probably faster ...

I always have to use the same block,
and the order of the objects that compose it is always the same ...
« Last Edit: April 02, 2022, 09:22:57 AM by domenicomaria »

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: setting dynamic properties
« Reply #10 on: April 04, 2022, 05:48:07 PM »
But help me to understand,
why it is not possible to use LM:SETDYNPROPS
to set the value of more the one properties, at the same time,
without finding this kind of problem  ...

The reason is because the "text-position X" dynamic parameter is encountered before the "distance-p1-p2" dynamic parameter in the list of objects returned by the getdynamicblockproperties method, and your dynamic block has a polar stretch action associated with the "distance-p1-p2" parameter which will affect the position of the text object.

Hence, the function will set the value of the "text-position X" parameter first, and then when the value of the "distance-p1-p2" parameter is modified, the value of the "text-position X" parameter is also changed by the actions associated with the "distance-p1-p2" parameter.

You can observe the same result in your most recent code by changing the order in which the parameters are modified.

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #11 on: April 04, 2022, 11:44:26 PM »
The reason is because the "text-position X" dynamic parameter is encountered before the "distance-p1-p2" dynamic parameter in the list of objects returned by the getdynamicblockproperties method, and your dynamic block has a polar stretch action associated with the "distance-p1-p2" parameter which will affect the position of the text object.

Hence, the function will set the value of the "text-position X" parameter first, and then when the value of the "distance-p1-p2" parameter is modified, the value of the "text-position X" parameter is also changed by the actions associated with the "distance-p1-p2" parameter.

You can observe the same result in your most recent code by changing the order in which the parameters are modified.
Thanks a lot Lee ...
... this means that when we change the values ​​associated with the properties of a dynamic block,
we have to pay attention to the order in which we modify these values ​​...

because the final result can depend from this order ...
... thanks. .. you are always enlightening ...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: setting dynamic properties
« Reply #12 on: April 05, 2022, 03:18:48 AM »
...Thanks a lot Lee ...
... this means that when we change the values ​​associated with the properties of a dynamic block,
we have to pay attention to the order in which we modify these values​​...
The order of the parameters is not a reliable thing, so don't use NTH as in: "(vlax-put (nth 2 dyn-blk-props) 'Value dst-12)"
If you use the real Mac Lee code:
Code: [Select]
(defun LM: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))))
        )
    )
)
you won't have any problem   :-)

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting dynamic properties
« Reply #13 on: April 05, 2022, 05:33:24 AM »
The order of the parameters is not a reliable thing, so don't use NTH as in: "(vlax-put (nth 2 dyn-blk-props) 'Value dst-12)"
If you use the real Mac Lee code:
you won't have any problem   :-)

Marco, in the first post, I use LM:SETDYNPROPS ...

But the code, did not work as aspected ...

And Lee Mac explained this ...

The problem is just the order ...

Try to play with the attached dynamic block and use the first code I posted

Lee Mac's code is perfect,
but we have to take into account how the dynamic block is made ...
... and in this case the order in which the values ​​are assigned to the properties
is important ...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: setting dynamic properties
« Reply #14 on: April 05, 2022, 09:19:16 AM »
.. but we have to take into account how the dynamic block is made ...
... and in this case the order in which the values ​​are assigned to the properties
is important ...
Domenico,
yes in your case the order of the parameters is important, as Lee stated:
Code: [Select]
The reason is because the "text-position X" dynamic parameter is encountered before the "distance-p1-p2" dynamic parameter in the list of objects returned by the
getdynamicblockproperties method, [b]and your dynamic block has a polar stretch action associated with the "distance-p1-p2" parameter [/b]which will affect the position of the text object.

Hence, the function will set the value of the "text-position X" parameter first, and then when the value of the "distance-p1-p2" parameter is modified, the value of the
"text-position X" parameter is also changed by the actions associated with the "distance-p1-p2" parameter.

I think the matter is more complicated and the result depends on the distance values, try this with various distances:
Code: [Select]
(defun C:K2    (   / p1 p2 ang-12 dst-12 ins-obj model-space)
  (setq p1 (getpoint     "\nfirst point : "  ) )
  (setq p2 (getpoint p1  "\nsecond point : " ) )
  (print "dst-12: ") (princ (setq dst-12  (distance p1 p2)   ang-12 (angle p1 p2) ))
  (setq model-space (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) )
  (setq ins-obj (vla-InsertBlock model-space (vlax-3d-point p1 ) "DB-LINE-DIM-X" 1.0 1.0 1.0 ang-12 ) )
  (print "Before: ") (prin1 (LM:getdynprops ins-obj))
  (LM:SETDYNPROPS ins-obj (list (cons "distance-p1-p2" dst-12) (cons "text-position X" 1.0 )))
  (print "After: ")  (prin1 (LM:getdynprops ins-obj))
  (princ)
)
(defun C:K3    (   / p1 p2 ang-12 dst-12 ins-obj model-space)
  (setq p1 (getpoint     "\nfirst point : "  ) )
  (setq p2 (getpoint p1  "\nsecond point : " ) )
  (print "dst-12: ") (princ (setq dst-12  (distance p1 p2)   ang-12 (angle p1 p2) ))
  (setq model-space (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) )
  (setq ins-obj (vla-InsertBlock model-space (vlax-3d-point p1 ) "DB-LINE-DIM-X" 1.0 1.0 1.0 ang-12 ) )
  (print "Before: ") (prin1 (LM:getdynprops ins-obj))
  (LM:SETDYNPROPS ins-obj (list (cons "text-position X" 1.0 ) (cons "distance-p1-p2" dst-12)))
  (print "After: ")  (prin1 (LM:getdynprops ins-obj))
  (princ)
)
Code: [Select]
Comando: K2
"dst-12: " 0.25188
"Before: " (("text-position X" . 1.5) ("text-position Y" . 0.0) ("distance-p1-p2" . 3.0) ("angle-p1-p2" . 0.0) ("Origin" 0.0 0.0) ("text-angle" . 0.0) ("Origin" 1.5 0.0) ("txt-mask-half-dx" . 0.275) ("Origin" 1.5 0.0) ("txt-mask-half-dy" . 0.1) ("Origin" 1.5 0.0))
"After: " (("text-position X" . 0.658089) ("text-position Y" . 0.0) ("distance-p1-p2" . 2.31618) ("angle-p1-p2" . 0.0) ("Origin" 0.0 0.0) ("text-angle" . 3.14159) ("Origin" 0.658089 0.0) ("txt-mask-half-dx" . 0.275) ("Origin" 0.658089 0.0) ("txt-mask-half-dy" . 0.1) ("Origin" 0.658089 0.0))

Comando: K3
"dst-12: " 0.25188
"Before: " (("text-position X" . 1.5) ("text-position Y" . 0.0) ("distance-p1-p2" . 3.0) ("angle-p1-p2" . 0.0) ("Origin" 0.0 0.0) ("text-angle" . 0.0) ("Origin" 1.5 0.0) ("txt-mask-half-dx" . 0.275) ("Origin" 1.5 0.0) ("txt-mask-half-dy" . 0.1) ("Origin" 1.5 0.0))
"After: " (("text-position X" . 0.658089) ("text-position Y" . 0.0) ("distance-p1-p2" . 2.31618) ("angle-p1-p2" . 0.0) ("Origin" 0.0 0.0) ("text-angle" . 3.14159) ("Origin" 0.658089 0.0) ("txt-mask-half-dx" . 0.275) ("Origin" 0.658089 0.0) ("txt-mask-half-dy" . 0.1) ("Origin" 0.658089 0.0))

Lee function always modify the values in the order of the parameters, but the order of the parameters is not always easy to keep it in different blocks...