Jump to content

Recommended Posts

Posted

Hello,
With the help of AI I am trying to make a .lsp script that insert specific block on every vertex of a polyline and orient two "arrows" to the previous and next vertex.
I try with different AI models and always I end up with error in Autocad (I use Autocad 2022) Error: "ActiveX Server returned the error: unknown name: "DYNAMICBLOCKPROPERTIES".
AI say that the block is not really a dynamic block, which I dont get, how block can be not really dynamic.

I am attaching both block and .lsp script. I hope someone will give me some advice what is wrong with the block or with .lsp script.
 

BlockInsert.lsp block.dwg

Posted

Maybe it's just that property doesn't exist on the specified object.

Posted (edited)

For a client did draw arrows I used a entmake pline so have control over the arrow sizes length and width. Its a case of setting the start as 0.0 and a length and an end arrow width. Yes matching angle of a pline and same layer.

 

Can you provide more information about how the arrows are to be shown at each vertice, length and width plus direction.

 

 

image.png.7556470a60fb9f543cfbdfc381834070.png

Edited by BIGAL
Posted

Hello thank you for your reply. 

May be I did not explain properly what I want to do. I will post some pictures may be they will help.

On the Block_1.jpg is how the drawing has to look like.

On the Block_2.jpg is the block it self when is edited.

 

So the script has to change "Angle" and "Angle1" so the so called arrows point to the previous and next block - Block_3.jpg

Block_2.jpg

Block_1.jpg

Block_3.jpg

Posted

Ok thats is very similar to what I was talking about, its easy to draw an arrow at a point along a pline, you can do this in a number of ways one of the easiest is to just use "V" rotated + - to to the angle between the points.

 

Which of these is correct ? You should post a dwg not an image, can then see sizes and offsets from vertices.

 

image.png.2d09261ead41015cf957bf4adf5daead.png

  • Like 1
Posted

I'd be forgetting AI for now, handy for snippets but still not quiet there.

 

Lee Mac has some great resources: 

https://lee-mac.com/dynamicblockfunctions.html

might be what you are looking for.

Also search this forum for Massoc Implementations which can be used to return a list of vertices.

 

 

(defun mAssoc ( key lst / result )
 (foreach x lst
   (if (= key (car x))
     (setq result (cons (cdr x) result))
   )
 )
 (reverse result)
)

 

Will give a list of points along a polyline where key in this case is 10, and list is the polyline entity description from maybe (entget (car (entsel)))

 

 

Dynamic blocks:

(defun LM:getvisibilitystate ( blk / vis )
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
)
(lm:getdynprops (vlax-ename->vla-object (car(entsel))) )

 

returns the format and names of dynamic block variables and setting them with:

 

(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))))
        )
    )
)
(lm:setdynprops (vlax-ename->vla-object (car(entsel))) (list (cons "Angle" 0) (cons "Angle2" pi)))

 

 

Inserting the blocks can be as simple as (command "insert" "Stylb_NN_nov" -Point- "" "" "")

where point is the points along the massoc returned list (ignore the 1st and last point)

and then use (entlast) in the setdynprops line instead of (car(entsel))

 

 

 

Might be a pointer to get you making something up.

Posted

Try this:

 

No error checking, or checking you have selected the correct polyline. Works only of LWPolylines - comment again if you want this to do 3d polylines as well.

I haven't put many notes in this as to how it works, but look through and see if it makes sense.

 

One thing I noticed is your sample block - to me - was an anonymous block name - which might have been the error you noticed (some technical stuff made it so) - as a fix I copied the block entities and created a new block, calling it "Arrow". You'll need to set your block name in the LISP below to the block you want to use (see (Setq MyBlockName "Arrow") line for what to change).

 

(defun c:blockinsert ( / ent MyEnt acount EntCoords MyBlock MyBlockName Ang1 Ang2)

;; Initial Values
  (setq MyBlockName "Arrow") ;; Change this to your block name

;;Sub functions
  (defun mAssoc ( key lst / result ) ;; Lee Mac: CadTutor forum
   (foreach x lst
     (if (= key (car x))
       (setq result (cons (cdr x) result))
     )
   )
   (reverse result)
  )

  (defun LM:getvisibilitystate ( blk / vis ) ;; Lee Mac
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
  )

  (defun LM:setdynprops ( blk lst / itm ) ;; Lee Mac
    (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))))
        )
    )
  )

  (defun SetAng ( Ang1 Ang2 MyEnt / ) ;; From Lee Macs LISPs. Change 'cons' "Angle", "Angle1" to suit dynamic block
    (lm:setdynprops (vlax-ename->vla-object MyEnt) (list (cons "Angle" Ang1) (cons "Angle1" Ang2))) ; Ang in radians
  )

  (defun AddBlock ( BName Pt XScale YScale ZScale / ) ;; Adds block to the drawing
    (setq NewBlock (entmakex (list
      '(0 . "INSERT")
      (cons 2 BName)
      (cons 10 Pt)
      (cons 41 XScale)
      (cons 42 YScale)
      (cons 43 ZScale)
      (cons 50 0);
    ))) ; end setq entmakex, list
    NewBlock
  )
;; End sub functions

  (setq Ent (car(entsel "Select LW Polyline")))
  (setq MyEnt (entget Ent))
  (if (or
      (equal (cdr (assoc 0 MyEnt)) "LWPOLYLINE")
    ) ; end or
    (progn
      (setq EntCoords (massoc 10 MyEnt))
      (setq acount 0)
      (while (< acount (length EntCoords))
        ;;Insert
        (setq MyBlock (AddBlock MyBlockName (nth acount EntCoords) 1 1 1) )
        ;;Ang1        
        (if (= acount 0) ; First point
          (progn
            (setq ang1 (angle (nth acount EntCoords) (nth (+ acount 1) EntCoords) )) ; = ang2
          ) ; end progn
          (progn
            (setq ang1 (angle (nth acount EntCoords) (nth (- acount 1) EntCoords) ))
          ) ; end progn
        ) ; end if

        ;;Ang2
        (if (= acount (- (length EntCoords) 1)) ; last point
          (progn
            (setq ang2 (angle (nth acount EntCoords) (nth (- acount 1) EntCoords) )) ; = ang1
            (setq ang2 (angle (nth (- acount 1) EntCoords) (nth acount EntCoords) ))
          )
          (progn
            (setq ang2 (angle (nth (+ acount 1) EntCoords) (nth acount EntCoords) ))
          )
        ) ; end if

        (SetAng Ang1 Ang2 (entlast)) ;; Sets dynamic block angle

        (setq acount (+ acount 1))
      ) ; end while
    )
    (progn
      (princ "Polyline not selected")
    ) ; end progn
  ) ; end if polyline

  (princ) ; exit quietly
)

 

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