Author Topic: Dynamic Blocks and Visual LISP  (Read 12529 times)

0 Members and 1 Guest are viewing this topic.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Dynamic Blocks and Visual LISP
« Reply #30 on: June 12, 2013, 08:37:50 AM »
Be a bit more patient, I'm busy typing!

Well, open the block in Block Edit then select one of those polar parameters. Open the properties palette and it will show you the names of the distance and angle parameters of each.

Now you can get/set those the same way you do with the visibility parameter. E.g.
Code: [Select]
_$ (setq eo (vlax-ename->vla-object (entlast)) )
#<VLA-OBJECT IAcadBlockReference 000000003c393bd8>
_$ (dyget eo "1 Leader ON")
nil
_$
_$ (dyget eo "1 Leader")
nil
_$ (dyget eo "1 Leader ")
#<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000003c4e6638>
_$ (vla-get-value (dyget eo "1 Leader "))
#<variant 5 1470.23133612937>
_$ (vlax-get (dyget eo "1 Leader ") 'value)
1470.23
Note, do a normal List on the block to find out the "real" names of those. Here you can see the parameter is actually called "1 Leader " including the space.

Note though, the "coordinates" is not X,Y position from origin. It's polar, like in a radius line of a circle. So you'd need some trigonometry or using the angle and distance function to convert between Cartesian & polar coordinates. The polar (built in) function only converts from polar to xy, my guess is you want it the other way round. So:
Code - Auto/Visual Lisp: [Select]
  1. (defun xy->polar (dx dy)
  2.   (list (distance '(0.0 0.0) (list dx dy))
  3.         (angle '(0.0 0.0) (list dx dy))))
The trig method becomes a bit more complex.

Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 385
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Dynamic Blocks and Visual LISP
« Reply #31 on: June 12, 2013, 09:14:11 AM »
If I can follow you I get one parameter (distance) what is with the angle ?

I was thinking it can go so here, I get new distance and angle and manipulate them in the Block - is it wrong?

Code: [Select]
(defun c:test ()
    (command "_insert" "knr"
             (setq insPt
                      (getpoint "\n Position No.!")) (getvar "DIMSCALE") (getvar "DIMSCALE") 0
                                         "1"
                                         "NAME"
             )
    (setq dis
             (if
                 (setq angl
                          (angle insPt
                                 (setq flagPt (getpoint "\n flag point! ")))
                 )
                 (distance insPt flagPt)
              )
    )

    ; Turn on  Leader 1
    (dySet (vlax-ename->vla-object (entlast)) "Visibility1" "1 Leader ON")

    (princ)
    )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Dynamic Blocks and Visual LISP
« Reply #32 on: June 12, 2013, 09:32:49 AM »
As I said, use the list command on one of those blocks to see what those parameters are truly called:
Quote
Command: LS LIST
Select objects: 1 found

Select objects:

                  BLOCK REFERENCE  Layer: "0"
                            Space: Model space
                   Handle = 39f7
       Block Name: "knr"
   Anonymous Name: "*U9"
                at point, X= 184359.0  Y=  35574.0  Z=      0.0
   X scale factor:       1.0
   Y scale factor:       1.0
   rotation angle:   0.00
   Z scale factor:       1.0
         InsUnits: Meters
  Unit conversion:    1000.0
  Scale uniformly: No
  Allow exploding: Yes
      Visibility1: 3 Leader ON
        1 Leader :    1470.2
           Angle1:     45.00
         2 Leader:    1470.2
           Angle2:      0.00
         3 Leader:    1470.2
           Angle3:    315.00


                  ATTRIBUTE  Layer: "0"
                            Space: Model space
                   Color: 1 (red)    Linetype: "BYLAYER"
                   Handle = 39f8
             Style = "SIMPLEX8"
        Annotative: No
             Font file = simplex.shx
            center point, X= 184366.3  Y=  35344.3  Z=      0.0
            height     500.0
             value Nr
Press ENTER to continue:
              .......
So then the 1st polar parameter actually consists of the distance named "1 Leader ", AND the angle named "Angle1".

Note this angle is listed as degrees, but when you obtain its value through lisp (or set it through lisp) it only works using radians.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 385
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Dynamic Blocks and Visual LISP
« Reply #33 on: June 12, 2013, 09:41:54 AM »
Sorry I donīt realy understand. I get your result as you described. But how can I use results from "Textscreen list". I doesnīt find them in entget-list or I have wrong?

cadplayer

  • Bull Frog
  • Posts: 385
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Dynamic Blocks and Visual LISP
« Reply #34 on: June 13, 2013, 02:03:51 AM »
Thanks irneb, I was tired yesterday. I could fix it.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Dynamic Blocks and Visual LISP
« Reply #35 on: June 13, 2013, 02:32:18 AM »
Sorry I donīt realy understand. I get your result as you described. But how can I use results from "Textscreen list". I doesnīt find them in entget-list or I have wrong?
Yes, that's the whole point of Tony's code - which you posted here. It's using ActiveX instead of entget & entmod. That's because dynamic block properties are only accessible through ActiveX in AutoLisp.

If you want to go the entget/entmod route through the raw DXF stuff, then look into the dictionaries attached to the block insert. Some of those point to the data for these parameters. But trying to figure them out is a huge task with no extra benefit over the ActiveX methods.

So you use Tony's defuns, or any others like mine (http://sourceforge.net/p/caddons/code/HEAD/tree/Blocks/BlockData.LSP) or Lee's (http://www.lee-mac.com/dynamicblockfunctions.html). They all do basically the same thing - make it easier to get / set parameter values through a single function call instead of performing multiple checks & assignments.

So using my functions, you need an ActiveX object reference to the block insertion's entity. Then you need to know the name of the Parameter or the index number.
Code: [Select]
_$ (setq bObj (vlax-ename->vla-object (entlast)))
#<VLA-OBJECT IAcadBlockReference 000000002d17f868>
_$ (Blocks:GetParameterValues bObj)
(("VISIBILITY1" . "3 Leader ON") ("1 LEADER " . 1470.23) ("ANGLE1" . 0.785398) ("ORIGIN" . #<safearray...>) ("2 LEADER" . 1470.23) ("ANGLE2" . 0.0) ("ORIGIN" . #<safearray...>) ("3 LEADER" . 1470.23) ("ANGLE3" . 5.49779) ("ORIGIN" . #<safearray...>))
_$ (Blocks:GetParamValue bObj "1 LEADER ")
1470.23
_$ (Blocks:GetParamValue bObj "ANGLE1")
0.785398
_$ (Blocks:PutParamValue bObj "ANGLE1" (* (/ 60.0 180.0) pi))
T
_$ (Blocks:PutParamValue bObj "1 LEADER " 4000.0)
T
_$ (Blocks:GetParamValue bObj "ANGLE1")
1.0472
_$ (Blocks:GetParamValue bObj "1 LEADER ")
4000.0
So here I changed the 1st leader to be at 60 degrees and 4000 units long.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 385
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Dynamic Blocks and Visual LISP
« Reply #36 on: June 13, 2013, 04:21:35 AM »
Very nice stuff, thank you so much for your offering :wink: