Jump to content

Rotate to Match View


Guest

Recommended Posts

Hi. I am using this code

 

; ROTOTXT.LSP
; Routine for rotating text to a the current viewtwist angle.
; 
; 


(defun c:ROV ( / ss2 i vta tmp)
  (vl-load-com)
  (prompt "\n Select TEXT and MTEXT to rotate ")
  (setq ss2 (ssget '((0 . "*TEXT")))
        i   0
        vta (- 0 (getvar "viewtwist"))
  )
  (repeat (sslength ss2)
    (setq tmp (vlax-ename->vla-object (ssname ss2 i)))
    (if (eq (vla-get-ObjectName tmp) "AcDbText")
      (progn
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp "Alignment" acAlignmentLeft)
      )
      (progn
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )
    )
    (setq i (1+ i))
  )
)

 

To rotate text to a the current viewtwist angle. I want to change this code to automatic select specific layer of text,mtext, and block  and rotate them to a the current viewtwist angle

 

i  try to change this line

 

(setq ss2 (ssget '((0 . "*TEXT")))

 

with this

 

  (setq ss2(ssget "_X" ((0 . "INSERT") (0 . "*TEXT") (8 . "LAYER1,LAYER2,LAYER3")))

 

but is not working. Can any one help?

 

Thanks

 

 

 

Link to comment
Share on other sites

hI mhupp . I test your code and i have this error .

 

Quote

; error: ActiveX Server returned the error: unknown name: "AttachmentPoint"

 

 

(defun c:ROV2 ( / ss2 i vta tmp)
  (vl-load-com)
  (setq ss2 (ssget "_X" '((-4 . "<OR") (0 . "INSERT") (0 . "*TEXT") (-4 . "OR>") (8 . "LAYER1,LAYER2,LAYER3")))
        i   0
        vta (- 0 (getvar "viewtwist"))
  )
  (repeat (sslength ss2)
    (setq tmp (vlax-ename->vla-object (ssname ss2 i)))
    (if (eq (vla-get-ObjectName tmp) "AcDbText")
      (progn
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp "Alignment" acAlignmentLeft)
      )
      (progn
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )
    )
    (setq i (1+ i))
  )
)

 

Edited by prodromosm
Link to comment
Share on other sites

5 minutes ago, prodromosm said:

hI mhupp . I test your code and i have this error .

 

 

 

(defun c:ROV2 ( / ss2 i vta tmp)
  (vl-load-com)
  (setq ss2 (ssget "_X" '((-4 . "<OR") (0 . "INSERT") (0 . "*TEXT") (-4 . "OR>") (8 . "LAYER1,LAYER2,LAYER3")))
        i   0
        vta (- 0 (getvar "viewtwist"))
  )
  (repeat (sslength ss2)
    (setq tmp (vlax-ename->vla-object (ssname ss2 i)))
    (if (eq (vla-get-ObjectName tmp) "AcDbText")
      (progn
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp "Alignment" acAlignmentLeft)
      )
      (progn
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )
    )
    (setq i (1+ i))
  )
)

 

 

Go through the logic .. it's a simple IF statement. Would you expect a block to have an attachment point?

image.thumb.png.befbf6f173dcf9968d91b055746360f4.png

Link to comment
Share on other sites

Try to figure it out !!! 🤓 

 

You have 900 posts here and almost 400 at TheSwamp. This problem should be fairly easy for you to solve by now IMO.

Link to comment
Share on other sites

On 11/9/2022 at 4:14 PM, prodromosm said:

Yes, but i want to work for text , mtext and block. How to do this !!!!

 

Thanks

 

To get you started. switch the if statement to cond

 

(defun c:ROV2 ( / ss2 i vta tmp)
  (vl-load-com)
  (setq ss2 (ssget "_X" '((0 . "INSERT,*TEXT") (8 . "LAYER1,LAYER2,LAYER3")))
        vta (- 0 (getvar "viewtwist"))
  )
  (foreach ent (mapcar 'cadr (ssnamex SS2))
    (setq tmp (vlax-ename->vla-object ent))
    (cond
      ((eq (vla-get-ObjectName tmp) "AcDbText")
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp "Alignment" acAlignmentLeft)
      )
      ((eq (vla-get-ObjectName tmp) "AcDb   ") ;mtext
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )
      ((eq (vla-get-ObjectName tmp) "AcDb   ") ;block
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp ) ;insertion point?
      )
    )
  )
  (princ)
)

 

Edited by mhupp
Link to comment
Share on other sites

Agree with ronjonp, at some point "I want" "I want" has to stop. Its not like your asking for help to solve a difficult problem, I ask at times and I have been at it for over 40 years. 

Link to comment
Share on other sites

Hi can any one help me how to make this code to work for text and mtext ?

 

(defun c:ROV2 ( / ss2 i vta tmp)
  (vl-load-com)
  (setq ss2 (ssget "_X" '((0 . "*TEXT,MTEXT") (8 . "LAYER1,LAYER2,LAYER3")))
          i   0
        vta (- 0 (getvar "viewtwist"))
  )
  (repeat (sslength ss2)
    (setq tmp (vlax-ename->vla-object (ssname ss2 i)))
    (if (eq (vla-get-ObjectName tmp) "AcDbText")
      (progn
        (vlax-put tmp "Rotation" vta)
        (vlax-put tmp "Alignment" acAlignmentLeft)
      )
      (progn
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )
    )
    (setq i (1+ i))
  )
) ;end defun

 

Thanks

 

Link to comment
Share on other sites

Yes i see it. I think tha this not incluse mtext

 

Quote

(setq ss2 (ssget "_X" '((0 . "INSERT,*TEXT") (0 . "*TEXT") (8 . "LAYER1,LAYER2,LAYER3")))

 

and here i try

 

      ((eq (vla-get-ObjectName tmp) "AcDbMTEXT") ;mtext
        (vlax-put tmp "Rotation" 0.0)
        (vlax-put tmp "AttachmentPoint" acAttachmentPointTopLeft)
      )

 

 

but didn't work. I don't know

 

Thanks

Link to comment
Share on other sites

I Messed up the ssget

 

(setq ss2 (ssget "_X" '((0 . "INSERT,*TEXT") (8 . "LAYER1,LAYER2,LAYER3"))) 

 

"AcDbBlockReference" for blocks

"AcDbMText" for Mtext

Link to comment
Share on other sites

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