See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Rotating value in dynamic block to zero

  1. #1
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Rotating value in dynamic block to zero

    Hi All
    I am working with a drawing that has numerous of the same dynamic block. The block is called "UV(2)" and it has to dynamic actions - one to rotate the tag and another to rotate a group attributes that side to one side of the block. The action name that I want to rotate to zero is called "Angle2". Attached is a routine I found on the internet that I have modified but I cannot get to work. I keep getting the following error: "** Error: Automation Error. Invalid input **." I tried putting quotes around the rotation value but that doesn't make a difference. Ideally, I want to rotate the attribute values to zero for all blocks in the drawing. Thatnk you very much.

    Manuel A. Ayala

    Code:
    (defun c:s2db (/ esb v vval sal salnth count)
    	(vl-load-com)
    	(setq esb nil)
    	(while (= esb nil)
    		(setq esb (entsel))
    		(if (/= (vlax-get-property (vlax-ename->vla-object (car esb)) "effectivename") "UV(2)")
    			(setq esb nil)
    		)
    	)
    	(setq obj (vlax-ename->vla-object (car esb)))
    	(setq v (vla-getdynamicblockproperties obj))
    	(setq vval (vlax-variant-value v))
    	(setq sal (vlax-safearray->list vval))
    	(setq salnth (length sal))
    	(setq count 0)
    	(while (< count salnth)
    		(if (= (vlax-get-property (nth count sal) "PropertyName") "Angle2")
    			(progn
    				(vlax-put-property (nth count sal) "Value" 0)(princ)
    				(setq count salnth)
    			)
    			(setq count (+ count 1))
    		)
    	)
    	(princ)
    )

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Change this one line to get the rotation value change to take effect:
    Code:
    (defun c:s2db (/ esb v vval sal salnth count)
    	(vl-load-com)
    	(setq esb nil)
    	(while (= esb nil)
    		(setq esb (entsel))
    		(if (/= (vlax-get-property (vlax-ename->vla-object (car esb)) "effectivename") "UV(2)")
    			(setq esb nil)
    		)
    	)
    	(setq obj (vlax-ename->vla-object (car esb)))
    	(setq v (vla-getdynamicblockproperties obj))
    	(setq vval (vlax-variant-value v))
    	(setq sal (vlax-safearray->list vval))
    	(setq salnth (length sal))
    	(setq count 0)
    	(while (< count salnth)
    		(if (= (vlax-get-property (nth count sal) "PropertyName") "Angle2")
    			(progn
    ;;;				(vlax-put-property (nth count sal) "Value" 0)(princ)
    				(vlax-put (nth count sal) "Value" 0.0)
    				(setq count salnth)
    			)
    			(setq count (+ count 1))
    		)
    	)
    	(princ)
    )
    To process multiple Blocks, simply change the code to allow for multiple selection and iterate that.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Hi BlackBox
    I changed my code to your suggestion and worked. I needed to evaluate the angle of the original block in order to correctly rotate the attributes. That is all working fine now. My problem now is that I am having trouble with correct way to evaluate an item from a list. Take a look at the line of code with ;; HERE'S THE ISSUE after it. Thanks.
    Manuel

    Code:
    (defun c:s2db (/ esb v vval sal salnth count)
    	(vl-load-com)
            (setq allblklst (ssget "x" (list (cons 0 "INSERT"))))
     (foreach item allblklst
            (setq esb (entget (ssname item (setq i (1+ i))))) ;; HERE'S THE ISSUE
            (setq valchk (cdr (assoc 50 (entget (car esb)))))
            (setq exrot (/ (* valchk 180.0) pi))
            (setq nrotval (* pi (/ (+ (- 360.0 exrot) 90.0) 180.0)))
    	(setq obj (vlax-ename->vla-object (car esb)))
    	(setq v (vla-getdynamicblockproperties obj))
    	(setq vval (vlax-variant-value v))
    	(setq sal (vlax-safearray->list vval))
    	(setq salnth (length sal))
    	(setq count 0)
    	(while (< count salnth)
    		(if (= (vlax-get-property (nth count sal) "PropertyName") "Angle2")
    			(progn
    				(vlax-put (nth count sal) "Value" nrotval)
    				(setq count salnth)
    			)
    			(setq count (+ count 1))
    		)
    	)
    )
    	(princ)
    )

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    You need to change your foreach function to a repeat function. You will need to repeat through the length of your selection set. You will want to set a variable for this length.

    You could also use a while function instead of the repeat function.

    You also never assigned a value to i, therefore your math will not work.

    If you are attempting to expand your previous code to allow it to work on a selection set, you may want to determine if the block selected has the correct EffectiveName property before doing all of the other math to save time in processing.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Hi Opie
    This routine is part of a larger conversion. The drawings that I will be running this routine on will have multiple copy of the same dynamic block. That is why I don't need to find the EffectiveName property for this function. I did change to code according to your suggestions but I am still getting an error message:
    ** Error: bad argument type: consp <Entity name: 2759c9a6030> **. I think it is right after I set the esb variable. Thanks.
    Manuel
    Code:
    (defun c:s2db (/ allblklst inc esb valchk exrot nrotval v vval sal salnth count)
      (vl-load-com)
      (setq allblklst (ssget "x" (list (cons 0 "INSERT"))))
      (setq inc 0)
      (repeat (sslength allblklst)
        (setq esb (ssname allblklst inc))
        (setq valchk (cdr (assoc 50 (entget (car esb)))))
        (setq exrot (/ (* valchk 180.0) pi))
        (setq nrotval (* pi (/ (+ (- 360.0 exrot) 90.0) 180.0)))
        (setq obj (vlax-ename->vla-object (car esb)))
        (setq v (vla-getdynamicblockproperties obj))
        (setq vval (vlax-variant-value v))
        (setq sal (vlax-safearray->list vval))
        (setq salnth (length sal))
        (setq count 0)
        (while (< count salnth)
          (if (= (vlax-get-property (nth count sal) "PropertyName") "Angle2")
    	(progn
    	  (vlax-put (nth count sal) "Value" nrotval)
    	  (setq count salnth)
    	)
    	(setq count (1+ count))
         )
       )
       (setq inc (1+ inc))
      )
    (princ)
    )

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    1

    Default Re: Rotating value in dynamic block to zero

    Slight modification of this old post:

    https://forums.augi.com/showthread.p...=1#post1234493

    This is a sub-function & custom command that will make it easier for you to roll out new custom commands, targeting specific dynamic blocks & their properties en-mass.

    Code:
    (vl-load-com)
    ;;;--------------------------------------------------------------------;
    ;;; Custom commands (block-specific):
    ;;; Example:
    ;;; (_SetDynProp "MyBlockName" "DynPropName" DynPropValue)
    (defun c:UV2->0 () (_SetDynProp "UV(2)" "Angle2" 0.0))
    
    ;;;--------------------------------------------------------------------;
    ;;; Sub-function (supports undo):
    (defun _SetDynProp (blockName dynPropName dynPropValue / *error* _GetDynamicBlocks acDoc blocks)
    
      (defun *error* (msg)
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (defun _GetDynamicBlocks (doc match / oBlocks blockName blocks)
        ;; Example:
        ;; (_GetDynamicBlocks acDoc "*MyBlockName*")
        (if (and (setq oBlocks (vla-get-blocks doc))
                 (setq match (strcase match))
            )
          (foreach space
                   (list (vla-get-modelspace doc) (vla-get-paperspace doc))
            (vlax-for x space
              (if
                (and
                  (= "AcDbBlockReference" (vla-get-objectname x))
                  (wcmatch
                    (strcase (setq blockName (vla-get-effectivename x))
                    )
                    match
                  )
                  (= :vlax-true
                     (vla-get-isdynamicblock
                       (vla-item oBlocks blockName)
                     )
                  )
                )
                 (setq blocks (cons x blocks))
              )
            )
          )
        )
        blocks
      )
    
      (if (setq blocks
                 (_GetDynamicBlocks
                   (setq acDoc (vla-get-activedocument (vlax-get-acad-object))
                   )
                   (strcase blockName)
                 )
          )
        (progn
          (vla-startundomark acDoc)
          (foreach block blocks
    	(foreach prop (vlax-invoke block 'getdynamicblockproperties)
    	  (if (= (vlax-get prop 'propertyname) dynPropName)
    	    (vlax-put prop 'value dynPropValue)				 ; don't forget to check for allowedvalues
    	  )
    	)
          )
        )
      )
      (*error* nil)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2022-04
    Posts
    2
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Place a point parameter. Open properties, set chain action to yes and grips to 0. Set a Move action to include the attribute and associate it with the point parameter. Create the rotation parameter, in the action set include the objects you want to rotate and include also the point parameter, not the attribute


  8. #8
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Thanks. I will try these functions.
    Manuel

  9. #9
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Hi BlackBox
    I am curious if it is possible to change the increment of a dynamic tag via AutoLisp? The block that I am working with has a dynamic angle field which is set to 45 degree increments. When I ran the routine it did not correctly adjust all of the tags that were at an angle that was 0, 90, 180, 270, 360. When I manually edit the block and changed the increment to 1 degree it worked beautifully. Can I edit the increment value with code? Thanks.
    Manuel

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Rotating value in dynamic block to zero

    Quote Originally Posted by cadconcepts View Post
    Hi BlackBox
    I am curious if it is possible to change the increment of a dynamic tag via AutoLisp? The block that I am working with has a dynamic angle field which is set to 45 degree increments. When I ran the routine it did not correctly adjust all of the tags that were at an angle that was 0, 90, 180, 270, 360. When I manually edit the block and changed the increment to 1 degree it worked beautifully. Can I edit the increment value with code? Thanks.
    Manuel
    I've just added the 45-degree increment to an angle in one of my own Blocks, manually rotated the Block to 90-degrees, and the code worked here.

    In some quick hunting, I'm not seeing a way to adjust the increment via Visual LISP (perhaps it's possible, not sure).

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 2013-07-26, 11:11 AM
  2. How can I set up Z-coordinate value to be zero and fixed in 2D?
    By thetlin24 in forum CAD Management - General
    Replies: 2
    Last Post: 2008-10-07, 05:55 PM
  3. Where is my Zero, Zero ?
    By cadclips81126 in forum Revit - Tutorials
    Replies: 5
    Last Post: 2006-05-15, 08:21 PM
  4. How can I make Project Zero match True Zero?
    By cparsons in forum Revit Architecture - General
    Replies: 2
    Last Post: 2006-03-23, 02:15 PM
  5. Globally set the elevation so that every object has a value of zero
    By robert.1.hall72202 in forum AutoCAD General
    Replies: 2
    Last Post: 2004-08-14, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •