Author Topic: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property  (Read 4679 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« on: February 05, 2013, 02:28:11 PM »
When using Lee Mac's routine to get the values of a dynamic block, I see that a Polar Stretch Pair parameter has an Origin, Distance1 and Angle1.
I can get and set the Origin if there is only on of these parameters.  The problem is if there is more than one.  Both have the same property name, "Origin".
Is there a way to separate these two so I can set the value of each separately?

Lee's Code to get the values:
Code - Auto/Visual Lisp: [Select]
  1. ;;---------------=={ Get Dynamic Properties }==---------------;;
  2. ;;                                                            ;;
  3. ;;  Returns a list of Dynamic Block Properties & Values.      ;;
  4. ;;------------------------------------------------------------;;
  5. ;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
  6. ;;------------------------------------------------------------;;
  7. ;;  Arguments:                                                ;;
  8. ;;  block - VLA Dynamic Block Reference Object                ;;
  9. ;;------------------------------------------------------------;;
  10. ;;  Returns: Association list of ((<prop> . <value>) ... )    ;;
  11. ;;------------------------------------------------------------;;
  12.  
  13. (defun LM:GetDynamicProps ( block )
  14.     (mapcar
  15.         (function
  16.             (lambda ( _prop )
  17.                 (cons (vla-get-propertyname _prop) (vlax-get _prop 'Value))
  18.             )
  19.         )
  20.         (vlax-invoke block 'GetDynamicBlockProperties)
  21.     )
  22. )
  23.  

Rabbit

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #1 on: February 05, 2013, 02:41:21 PM »
You should not need to modify the Origin Dynamic Block Property for a Dynamic Block Parameter in order to change the value of the Parameter; the Origin is the position of the Parameter within the Block Definition.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #2 on: February 05, 2013, 02:51:10 PM »
Maybe with this:
Code - Auto/Visual Lisp: [Select]
  1. ;; Tony Tanzillo
  2. ;; Get a single dynamic block property object by name
  3. ;;
  4. (defun GetDynBlockRefProperty (DynBlockRef Name)
  5.    (vl-some
  6.      '(lambda (property)
  7.          (if (eq (vlax-get-property property 'PropertyName) Name)
  8.             property
  9.          )
  10.       )
  11.       (vlax-safearray->list
  12.          (vlax-variant-value
  13.             (vla-getDynamicBlockProperties DynBlockRef)
  14.          )
  15.       )
  16.    )
  17. )
  18.  

Rabbit

  • Guest
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #3 on: February 05, 2013, 02:54:23 PM »
Not the block's origin, the origin of the "Polar Stretch Pair".  Attached is the icon in the Authoring Palette and what it looks like in the drawing space.

When this was drawn, the Origin of the Polar Parameter (dimension symbol) is to the right.  It was the first click to place it.  To get the other point, it looks like it's derived from a Distance and an Angle from that first point.

Start a new drawing, open up the Block Editor, place a couple of those in the dynamic block, save it in a drawing, and then see if you can change the points/grip locations via lisp.

Hopefully this makes sense.  Let me know if your not understanding me.  It's harder to explain than I thought.

Rabbit

Rabbit

  • Guest
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #4 on: February 05, 2013, 03:14:17 PM »
I did a little test.  When I use Lee's LM:GetDynamicProps, I see that the list has the Parameter name "Distance1" the the angle to the next point "Angle1 and then it has the Origin.  Okay, I can work with that with a little help from you guys.  If I can find the Nth of the parameter's name, then I could use (nth (+ Foundnth 3)) to get the origin.  I just not sure how to find the position of the parameter's name from list.

What's the collective think?

--EDIT--
Found a way:
Code - Auto/Visual Lisp: [Select]
  1. (setq PList (LM:GetDynamicProps (vlax-ename->vla-object (entlast))))
  2. (setq Origin (nth (+ 2 (vl-position (assoc "Distance2" PList) PList)) PList))
  3.  

--EDIT2--
Jumped the gun.  I can access the origin, but not how to set it.  I'm still lost on that front.

Rabbit
« Last Edit: February 05, 2013, 03:25:33 PM by Rabbit »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #5 on: February 05, 2013, 06:52:33 PM »
Not the block's origin, the origin of the "Polar Stretch Pair".

I understood what you were referring to, however, as I say, you needn't modify the Origin Property Object of the Polar Stretch parameter in order to alter the parameter values for a dynamic block reference.

Consider the following example:
In the GIF below, the grey circle & red line form a dynamic block, and the red line has a Polar Stretch Parameter applied to it.



I first demonstrate altering the Polar Stretch parameter manually by moving the grip; I then use the following code to alter the parameter programmatically:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / apn dpn dsp ins obj prn )
  2.     ;; Polar Stretch Dynamic Parameter Property Names:
  3.     (setq dpn "Distance1" ;; Distance Name
  4.           apn "Angle1"    ;; Angle Name
  5.     )
  6.     (if
  7.         (and
  8.             (setq obj (car (entsel "\nSelect Dynamic Block with Polar Stretch Parameter: ")))
  9.             (setq obj (vlax-ename->vla-object obj))
  10.             (= "AcDbBlockReference" (vla-get-objectname obj))
  11.             (= :vlax-true (vla-get-isdynamicblock obj))
  12.             (setq ins (trans (vlax-get obj 'insertionpoint) 0 1))
  13.             (setq dsp (getpoint ins "\nSpecify New Stretch Distance & Angle: "))
  14.         )
  15.         (foreach prop (vlax-invoke obj 'getdynamicblockproperties)
  16.             (setq prn (strcase (vla-get-propertyname prop)))
  17.             (cond
  18.                 (   (= prn (strcase dpn))
  19.                     (vla-put-value prop (vlax-make-variant (distance ins dsp)))
  20.                 )
  21.                 (   (= prn (strcase apn))
  22.                     (vla-put-value prop (vlax-make-variant (angle ins dsp)))
  23.                 )
  24.             )
  25.         )
  26.         (princ "\nInvalid response or selected object is not a Dynamic Block.")
  27.     )
  28.     (princ)
  29. )

[ Modify the Polar Stretch Parameter property names as required for testing ]

Rabbit

  • Guest
Re: Set Dynamic Block "Polar Stretch Pair" Parameter Origin Property
« Reply #6 on: February 06, 2013, 09:20:06 AM »
Yes Lee, you are correct, as always.  I was able to get the same thing as you with one end.  I can't tell, but did you you a regular 'polar stretch' or a 'polar stretch pair'? I've been working with a 'polar stretch pair'.  The only big difference I see in the two is a second stretch box and showing a grip.

Now to really wow me, in your example, move the other grip, the origin, using code.  And as a encore, do it for more than one of these parameters.

As always, thanks for the help.
Rabbit