Rotating object using two parameters. North Arrow

Rotating object using two parameters. North Arrow

Anonymous
Not applicable
1,354 Views
6 Replies
Message 1 of 7

Rotating object using two parameters. North Arrow

Anonymous
Not applicable

Hey there,

 

I am trying to write a .lisp to automatically rotate my north arrow in paper space, to represent the north (viewtwist) of the modelspace. I have been able to get the two values i need, but need some help in using one value to change the other (objects rotation).

 

I have managed to get the following and would like the first lisp, to be the rotation value for the second code (the handent of the north arrow).

 

If someone can help link these two together that would be great!

 

Thanks.

 

;get viewtwist value/angle
(defun c:vt()
(setq viewtwist(* (getvar"viewtwist") (/ 180.0 3.1415)))
)

;returns the the viewtwist angle in degrees.

 

 

;show arrow 50 value
(defun c:arsel()
(setq arrowsel(entget (handent "202c938")))
(setq arrowdir (assoc 50 arrowsel))
)

;returns the the arrow's angle in radians.

0 Likes
1,355 Views
6 Replies
Replies (6)
Message 2 of 7

dlanorh
Advisor
Advisor

Why are you approximating "pi" when pi is a built in contstant variable in autolisp?
Why are you converting the viewtwist angle to degrees when it needs to be in radians to set the angle?

How are you getting the blocks handle? It will be different in each drawing.
Is the north arrow block constructed correctly to allow the angle to be "plugged in" or does the angle need converting? A sample drawing containing just the north arrow block in paperspace saved in AutoCAD2010 would be useful.

It would be far easier to just select the block, then a couple of lines of code would set the blocks angle.

I am not one of the robots you're looking for

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hey there!

Thanks for getting back to me. Should have stated, I'm new to autolisp.

I was appx'ing pi to be able to input it into the block's 'rotation' property somehow.

I was using handent then using the entity handle (5). You are correct, when i try to use this in another drawing it doesn't work. I thought only the entity name changed.

 

This is the lisp i created to that was working within one drawing.

 

(defun c:rn()

(setq tw (entget (handent "2026573")))
(setq new (cdr (assoc 0 tw)))
(cond
((= new "VIEWPORT")(setq rt(cdr(assoc 51 tw))))
((= new "LWPOLYLINE")(setq temp (entget(cdr (assoc 330 tw))))(setq rt(cdr(assoc 51 temp))))
)
(setq elist(entget (handent "202c938")))
(setq elist(subst (cons 50 rt)(assoc 50 elist) elist))
(entmod elist)
(princ)
)

 

if you know how to achieve this, it might be easier to tell me how rather than working with my sloppy code! HA 😛

 

Dwg attached

 

Thanks again.

0 Likes
Message 4 of 7

dlanorh
Advisor
Advisor
I'll take a look after my meeting, around midday here (Europe). I'll fully document my code.

I am not one of the robots you're looking for

0 Likes
Message 5 of 7

dlanorh
Advisor
Advisor

OK, try this. It assumes modelspace is twisted using "DVIEW", and should be run in modelspace.

 

(defun c:r2vt( / c_doc a_units vt_ang ss)
  (vl-load-com)
  (setq c_doc (vla-get-activedocument(vlax-get-acad-object))
        a_units (getvar 'aunits)                              ;gets the current angular units setting and stores it
  );end_setq
  (setvar 'aunits 3)                                          ;sets angular units to radians
  (setq vt_ang (getvar 'viewtwist))                           ;gets viewtwist angle in radians
  (setvar 'aunits a_units)                                    ;resets angular units to entry state
  (setq ss (ssget "_X" '((0 . "INSERT") (2 . "North Arrow"))));gets a selectionset of all "North Arrow" blocks in drawing
  (vlax-for blk (vla-get-activeselectionset c_doc)            ;gets the active selection set as a collection of objects and loop through 
    (if (vlax-property-available-p blk 'rotation T)           ;if the object has a rotation property and it is writeable
      (vlax-put-property blk 'rotation vt_ang)                ;give the object (block) the rotation angle 
    );end_if
  );end_for
  (setq ss nil)
  (princ)
);end_defun  
  

This works for me in 2012 with modelspace twisted. Any problems get back to me.

I am not one of the robots you're looking for

0 Likes
Message 6 of 7

CodeDing
Advisor
Advisor

@Anonymous,

 

Why not insert a north arrow from the Layout Tools? then select your custom North arrow if you like. You select which VP you want it attached it. VERY easy process. Plus, you don't have to worry about updating it.

 

image.png

image.png

image.png

 

 

Best,

~DD

0 Likes
Message 7 of 7

danglar
Advocate
Advocate

… with some improvements..

(defun c:na( / c_doc a_units vt_ang ss)
  (vl-load-com)
(alert "\nYo must to be in a floating viewport to set North Arrow rotation angle...")
  (setq c_doc (vla-get-activedocument(vlax-get-acad-object))
        a_units (getvar 'aunits)                              ;gets the current angular units setting and stores it
  );end_setq
  (setvar 'aunits 3)                                          ;sets angular units to radians
  (setq vt_ang (getvar 'viewtwist))                           ;gets viewtwist angle in radians
  (setvar 'aunits a_units) 

   (setq ss (ssget "X" (list '(2 . "FRMARROW") (cons 410 (getvar "ctab")))))     ;gets a selection set of  "North Arrow" blocks in current layout


  ;(setq ss (ssget "_X" '((0 . "INSERT") (2 . "FRMARROW"))))   ;gets a selectionset of all "North Arrow" blocks in drawing
  (vlax-for blk (vla-get-activeselectionset c_doc)            ;gets the active selection set as a collection of objects and loop through 
    (if (vlax-property-available-p blk 'rotation T)           ;if the object has a rotation property and it is writeable
      (vlax-put-property blk 'rotation vt_ang)                ;give the object (block) the rotation angle 
    );end_if
  );end_for
  (setq ss nil)
  (princ)
);end_defun 
(c:na) 

1. warning about floating viewport

 

2. rotate north arrow block in current viewport only

0 Likes