Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp for dynamic block - rotate action

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
yu85.info
1083 Views, 23 Replies

Lisp for dynamic block - rotate action

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

 

Tags (3)
23 REPLIES 23
Message 2 of 24
Sea-Haven
in reply to: yu85.info

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) 

 

Message 3 of 24
yu85.info
in reply to: Sea-Haven

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)

    )

)

Message 4 of 24
pbejse
in reply to: yu85.info


@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?

Message 5 of 24
yu85.info
in reply to: pbejse

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.

 

Message 6 of 24
Sea-Haven
in reply to: yu85.info

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

Message 7 of 24
yu85.info
in reply to: Sea-Haven

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

Thanks agian

Message 8 of 24
Moshe-A
in reply to: yu85.info

@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)
)

 

 

Message 9 of 24
yu85.info
in reply to: Moshe-A

Thank you sir, I got this message:

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

Message 10 of 24
Moshe-A
in reply to: yu85.info

 

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

 

 

Message 11 of 24
yu85.info
in reply to: Moshe-A

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

Message 12 of 24
Moshe-A
in reply to: yu85.info

@yu85.info ,

 

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

 

 

Message 13 of 24
yu85.info
in reply to: Moshe-A

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

Message 14 of 24
yu85.info
in reply to: pbejse

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

Message 15 of 24
yu85.info
in reply to: Moshe-A

can you see the difference now sir?

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

Message 16 of 24
pbejse
in reply to: yu85.info


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

 

 

 

 

 

Message 17 of 24
yu85.info
in reply to: pbejse

look at the PS:

yu85info_0-1720605749229.png

If you could remove the solution mark

Thanks

Message 18 of 24
pbejse
in reply to: yu85.info

OH my 😲 You are right! 

How did that happened?  sorry about that 😀

 

 

Message 19 of 24
Moshe-A
in reply to: yu85.info

@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

 

Message 20 of 24
yu85.info
in reply to: Moshe-A

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 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report