Lisp for dynamic block - rotate action

yu85.info
Advocate

Lisp for dynamic block - rotate action

yu85.info
Advocate
Advocate

Hi, I have this DWG attached .I need to make this drawing a block that some objects can be rotated (from A to B). This is just an example the actual drawing is more complex.

Is there a way to create a lisp routine so at first I will choose the elements i need to be with a rotate parameter and then the entire drawing and the result B will come up?

Thanks you very much for your help

 

0 Likes
Reply
Accepted solutions (1)
1,463 Views
23 Replies
Replies (23)

Sea-Haven
Mentor
Mentor

1st step is get a copy of Lee-mac Dynamic block properties, you can use the code to set the value of Angle1. 

 

 

(defun LM:setdynpropvalue ( blk prp val )


(LM:setdynpropvalue blk "Angle1" ang) 

 

yu85.info
Advocate
Advocate

Thanks sir, this is what I found but still cant understand how to modify it to achieve the whole block so that the entire drawing will be included in the block but just some of them will rotate.

;; Set Dynamic Block Property Value - Lee Mac

;; Modifies the value of a Dynamic Block property (if present)

;; blk - [vla] VLA Dynamic Block Reference object

;; prp - [str] Dynamic Block property name (case-insensitive)

;; val - [any] New value for property

;; Returns: [any] New value if successful, else nil

 

(defun LM:setdynpropvalue ( blk prp val )

    (setq prp (strcase prp))

    (vl-some

       '(lambda ( x )

            (if (= prp (strcase (vla-get-propertyname x)))

                (progn

                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))

                    (cond (val) (t))

                )

            )

        )

        (vlax-invoke blk 'getdynamicblockproperties)

    )

)

0 Likes

pbejse
Mentor
Mentor

@yu85.info wrote:
...to achieve the whole block so that the entire drawing will be included in the block but  just some of them will rotate.

I'm having a hard time understanding this @yu85.info.

entire drawing will be included in the block?  Does that mean after the selected dynamic blocks are rotated, convert all the objects on model space to  a block?

yu85.info
Advocate
Advocate

Thanks, I will explain. The entire drawing should eventually be a dynamic block which some objects in it will be able to rotate and some not.

 

0 Likes

Sea-Haven
Mentor
Mentor

So end result is a nested block. No idea if you can get at dynamic blocks. Post a dwg with nested block.

yu85.info
Advocate
Advocate

I am not quite sure I understand what is a nested block but in this DWG attached there is the final result.

Thanks agian

0 Likes

Moshe-A
Mentor
Mentor

@yu85.info hi,

 

check this 😀

 

Moshe

 

 

(defun c:mlro (/ adoc ss0 ss1 ang bname ename)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndoMark adoc)
  
 (princ "\nPick a block...") 
 (if (and
       (setq ss0 (ssget ":s:e+." '((0 . "insert"))))
       (setq ang (getangle "\nRotation angle: "))
     )
  (progn
   (setq bname (vla-get-name (vlax-ename->vla-object (ssname ss0 0))))
   (if (setq ss1 (ssget "_x" (list '(0 . "insert") (cons '2 (strcat bname ",`*U*")) '(410 . "Model"))))
    (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
     (if (= (getpropertyvalue ename "isDynamicBlock") 1)
      (setpropertyvalue ename "AcDbDynBlockPropertyAngle1" ang)
     ); if
    ); foreach  
   ); if
  ); progn
 ); if

 (vla-endUndoMark adoc) 
 (vlax-release-object adoc)
  
 (princ)
)

 

 

yu85.info
Advocate
Advocate

Thank you sir, I got this message:

Pick a block...
Select objects:
Rotation angle: 360
ADS request error

0 Likes

Moshe-A
Mentor
Mentor

 

Are you selecting dynamic block?

i just update my code so copy & paste it again

also if the dynamic property name is not "angle1", it won't work

 

 

yu85.info
Advocate
Advocate

I appreciate your help. I think I have not explained myself well.

I attached a new DWG's. All the objects in the drawing should be in one block. The objects in yellow  should be with the ability to rotate. The lisp I am looking should ask me to pick objects (I will choose all the yellow ones) to pick a point (I will pick a point)  and set this point to a be rotate parameter of  an angle of 360 for all the yellow ones in the block.

I attached a DWG of "Before" and a DWG of "After".

Of course that has been done manually. I am searching for an automatic way.

Thanks again for your time sir

0 Likes

Moshe-A
Mentor
Mentor

@yu85.info ,

 

before.dwg and after.dwg are exactly the same drawings.

 

 

yu85.info
Advocate
Advocate

before.dwg the drawing is not a block

after.dwg the drawing is a dynamic block with rotation on some of the objects in the block

0 Likes

yu85.info
Advocate
Advocate

sir, you marked my question as a solution but it has not been solved

0 Likes

yu85.info
Advocate
Advocate

can you see the difference now sir?

for some reason someone marked it as solved but it has not have been solved

0 Likes

pbejse
Mentor
Mentor

@yu85.info wrote:

sir, you marked my question as a solution but it has not been solved


Are you sure it was me? I would not knowingly marked somebody else's solution especially if i  have nothing to do with it? Its not even on my list of recent activity. 

 

That is very strange. Anyhoo, i can remove the "accepted solution"  if you insist.

 

 

 

 

 

yu85.info
Advocate
Advocate

look at the PS:

yu85info_0-1720605749229.png

If you could remove the solution mark

Thanks

0 Likes

pbejse
Mentor
Mentor

OH my 😲 You are right! 

How did that happened?  sorry about that 😀

 

 

0 Likes

Moshe-A
Mentor
Mentor

@yu85.info 

 

first this thread is still not closed

 

second check this one 😀

 

At select objects pick  the objects you want to be in your dynamic block (you do not care about block name at all?)

it selects only those yellow objects. also you need to specify the Rotation base point: for the dynamic property rotation (angle1)

 

work?

 

Moshe

 

(defun c:WrapDynBlk (/ genBlockName ss p0 bname)

 (defun genBlockName (/ name return)
  (setq name "$temp")

  (setq i 0)
  (while (tblsearch "block" (setq return (strcat name (itoa i))))
   (setq i (1+ i))
  )

  return 
 ); genBlockName


 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (and
       (setq ss (ssget '((62 . 2))))
       (setq p0 (getpoint "\nRotation base point: "))
     )
  (progn
   (setq bname (genBlockName))
   
   (command "._block" bname "0,0,0" "_si" ss)
   (command "._bedit" bname)
   (command "._bparameter" "_rotation" p0 0.5 "" "" "")
   (command "._bactiontool" "_rotate" (polar p0 (/ pi 4) 0.5) "_si" "_all")
   (command "._bclose" "_save")
   (command "._insert" bname "0,0,0" 1 1 0)
  ); progn 
 ); if


 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ "\nDone.")
 (princ)
); c:WrapDynBlk

 

yu85.info
Advocate
Advocate

Hi, first of all it works prefect! but sorry for my rudeness... is it possible to add a second selection which will include the other objects in the drawing in the block (the yellow ones, I select, will be the only one who can  be rotate)

And if it is not to hard to add an option to give a name to the block

Thank you so much for your time 

0 Likes