Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Command to rotate General Note Label

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
htls69
1245 Views, 20 Replies

Command to rotate General Note Label

Trying to create a lsp command that will rotate a general note label

 

we have one that rotates Points ie z1, z2, z3, z4 That rotates the point to the respective quadrant

 

That lisp is below

 

;;; point rotation quadrant 1
(defun c:Z1 (/ doc pt sourcept ss ss2)
(setq rlang (- (* pi 0.25) (getvar "viewtwist")))
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
    (princ "\n....select Points to change: ")
    (if (setq ss (ssget '((0 . "AECC_COGO_POINT"))))
	(while (> (sslength ss) 0)
	  (setq pt (vlax-ename->vla-object (ssname ss 0)))
	  (vlax-put pt 'labelrotation rlang)
	  (ssdel (ssname ss 0) ss)
	)
      )
    )
  )
  (vla-endundomark doc)
  (princ)
)

If someone could help me that would be awesome.

 

I would like to have 4 lsp routines Like-- L1, L2, ,L3, L4 

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
20 REPLIES 20
Message 2 of 21
Jeff_M
in reply to: htls69

Unfortunately the Rotation property is not exposed for the Note Label in the COM API. This can be done using .NET, however. Attached is a zip file with a small .NET dll. Be sure to Unblock the zip file after downloading by locating the file in File Explorer, rt. click, properties, General tab, Unblock near the bottom of the dialog. You can create as many small lisps to call it with whatever rotation angle you wish. Here the one for 45 degrees:

(defun c:N1 (/ rlang )
   (setq rlang (- (* pi 0.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

Add a line similar to this to your acad.lsp file so the NoteLabelRotate lisp function will always be available:

(netload "c:\\LocationOfMyCustomFiles\\RotateNoteLabels.dll")
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 21
htls69
in reply to: Jeff_M

I added it like this

 

(defun S::Startup ()
(princ "Changing VARIABLES...")
(setvar "FILEDIA" 1)
(setvar "SAVETIME" 5)
(setvar "SAVEFIDELITY" 1)
(setvar "PEDITACCEPT" 1)
(setvar "MAXSORT" 8000)
(setvar "OSNAPZ" 1)
(setvar "FACETRES" 10)
(setvar "ISOLINES" 2047)
(setvar "PDMODE" 2)
(netload "T:\ACTION\RotateNoteLabels.dll")
(command "VIEWRES" "Y" 20000)
(command "UCSICON" "ON")
(command "AUDITCTL" "0")
(command "_-PLOTSTAMP" "_LOG" "_NO" "PLOT.LOG" "")
)

 but i am getting this when it loads

 

Command: Changing VARIABLES...Regenerating model.
; error: no function definition: NETLOAD
Command:

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 4 of 21
htls69
in reply to: Jeff_M

ok i tried changing the angle but it does not change the rotation

 

(defun c:N1 (/ rlang )
   (setq rlang (- (* pi 0.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

Command: N1
Select NoteLabels to rotate -343°-23'-15" degrees: 1 found
Select NoteLabels to rotate -343°-23'-15" degrees:

 

 

(defun c:N1 (/ rlang )
   (setq rlang (- (* pi 0.50) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )


Command: (LOAD "T:/ACTION/n1.lsp") C:N1
Command: n1
Select NoteLabels to rotate -253°-23'-15" degrees: 1 found
Select NoteLabels to rotate -253°-23'-15" degrees:

 

 

 

but label stays at 000°00'00"

 

Annotation 2020-02-07 121753.jpg

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 5 of 21
Jeff_M
in reply to: htls69

Sorry about the wrong directions for adding to the acad.lsp file. Netload is a command, so needs to be used like this:

(command ".Netload" "pathtothefile\\filename.dll")

 

As for not changing the rotation, it's working as expected here. 

 

I just found where it doesn't work...when this:

(- (* pi 0.25) (getvar "viewtwist"))

returns a negative value, the API uses 0. Attached is a lightly modified version that ensures the value is positive which appears to work for all cases.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 21
htls69
in reply to: Jeff_M

It is not loading when the drawing starts. Had to load it myself with netload.

 

.Netload Assembly file name: T:ACTIONRotateNoteLabels.dll Unable to load T:ACTIONRotateNoteLabels.dll assembly.

 

 

Command: (LOAD "T:/ACTION/n1.lsp") C:N1
Command: N1
; error: no function definition: NOTELABELROTATE
Command:
Command: N1 ; error: no function definition: NOTELABELROTATE
Command:
Command: NETLOAD
Command: N1
Select NoteLabels to rotate -118°-23'-15" degrees: 1 found
Select NoteLabels to rotate -118°-23'-15" degrees:
Command:
Command:
Command: (LOAD "T:/ACTION/n1.lsp") C:N1
Command: N1
Select NoteLabels to rotate -163°-23'-15" degrees: 1 found
Select NoteLabels to rotate -163°-23'-15" degrees:
Command:
Command:

 

 

The angle is still not changing

 

Annotation 2020-02-07 152230.jpg

 

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 7 of 21
htls69
in reply to: htls69

file i am using

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 8 of 21
htls69
in reply to: htls69

I got it to autoload with registry

 
Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 9 of 21
Jeff_M
in reply to: htls69

OK, good. The attached version should work for you. Tested in your drawing and it worked on all of the Note Labels I selected.

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 21
htls69
in reply to: Jeff_M

ok now i just need a little help with the lsp

 

n4    |    n1

-----------

n3    |    n2

 

need to rotate labels to quadrant angles n1=    45 degrees of the current view

                                                                         n2= 135 degrees of the current view

                                                                        n3= 225 degrees of the current view

                                                                        n4= 315 degrees of the current view

 

(defun c:N1 (/ rlang )
   (setq rlang (- (* pi 0.0) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N2 (/ rlang )
   (setq rlang (- (* pi -0.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N3 (/ rlang )
   (setq rlang (- (* pi -0.75) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N4 (/ rlang )
   (setq rlang (- (* pi -1.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

Thanks for all your help on this.

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 11 of 21
Jeff_M
in reply to: htls69

This works for me:

(defun c:N1 (/ rlang )
   (setq rlang (- (* pi 0.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N2 (/ rlang )
   (setq rlang (- (* pi 0.75) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N3 (/ rlang )
   (setq rlang (- (* pi 1.25) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N4 (/ rlang )
   (setq rlang (- (* pi 1.75) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )
Jeff_M, also a frequent Swamper
EESignature
Message 12 of 21
Jeff_M
in reply to: Jeff_M

I didn't look at your diagram, Allen. So the lisps don't match what you were looking for. Just change the defuns to match....so my N4 should be N2 and N2 should be N4
Jeff_M, also a frequent Swamper
EESignature
Message 13 of 21
htls69
in reply to: Jeff_M

they need to be at 45 to the current view in the drawing and they are direct up-right-down-left

 

n1=ne 

n2=se

n3=sw

n4-nw

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 14 of 21
Jeff_M
in reply to: htls69

Using your drawing and the lisps I posted they do exactly that...45 degrees to the current view.
Jeff_M, also a frequent Swamper
EESignature
Message 15 of 21
htls69
in reply to: Jeff_M

See screencast below

 

https://autode.sk/39pz9Wh

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 16 of 21
Jeff_M
in reply to: htls69

You are selecting NoteLabels whose contents are set to be at 45 degrees, so rotating the label 45 degrees makes it 90 degrees....

2020-02-10_15-17-45.png

 

Try it with one of the General Text notes, such as the Lawn labels, and you will see it works as expected.

Jeff_M, also a frequent Swamper
EESignature
Message 17 of 21
Jeff_M
in reply to: Jeff_M

If you want those labels with the set rotation of 45 degrees to always show at 45 to the view, change the LabelStyle Orientation Reference property to View instead of World Coordinate System.
Jeff_M, also a frequent Swamper
EESignature
Message 18 of 21
htls69
in reply to: Jeff_M

I don't want it to rotate the current label i want it to set a fixed angle  based on the current view.

 

like this one does for points

;;; point rotation quadrant 1
(defun c:Z1 (/ doc pt sourcept ss ss2)
(setq rlang (- (* pi 0.25) (getvar "viewtwist")))
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
    (princ "\n....select Points to change: ")
    (if (setq ss (ssget '((0 . "AECC_COGO_POINT"))))
	(while (> (sslength ss) 0)
	  (setq pt (vlax-ename->vla-object (ssname ss 0)))
	  (vlax-put pt 'labelrotation rlang)
	  (ssdel (ssname ss 0) ss)
	)
      )
    )
  )
  (vla-endundomark doc)
  (princ)
)

 

 

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 19 of 21
Jeff_M
in reply to: htls69

Allen, it is doing exactly that. Try the Point lisp Z1 on a Point whose label style's text contents are rotated 45 degrees. You will see the same thing you do with the tool I provided for the Notes.

See message 16 above.
Jeff_M, also a frequent Swamper
EESignature
Message 20 of 21
Jeff_M
in reply to: Jeff_M

You can get this to work with NoteLabels having the 45 degrees already set in the style by creating new calling lisps at 90 degree increments:

(defun c:N1R (/ rlang )
   (setq rlang (- (* pi 0.0) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N4R (/ rlang )
   (setq rlang (- (* pi 0.5) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N3R (/ rlang )
   (setq rlang (- (* pi 1.0) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )

(defun c:N2R (/ rlang )
   (setq rlang (- (* pi 1.5) (getvar "viewtwist")))
   (NoteLabelRotate rlang)
   (princ)
  )
Jeff_M, also a frequent Swamper
EESignature

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report