Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
richie.hodgson
Posts: 214
Registered: ‎11-05-2008
Message 1 of 7 (188 Views)

Orient "north" block

188 Views, 6 Replies
09-19-2012 08:37 PM

Hi I am trying to insert a norht block oriented on two selected points with the following

 

(defun c:North ( / ss )
 ;Orientate North Symbol
 (setq oldos (getvar "osmode"))
 (setq blk (vlax-ename->vla-object (car (entsel "\nChoose Object:"))))
  (setq xy (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint blk))))
 ;errase block here
 (setvar "osmode" 1)
 (setq rot (getangle "\nPlease Select End Points :"))
 (setq rot (* pt2 (/ 180 pi)))
 (setq rot (- 360 pt2))
 (setvar "osmode" 0)
 (command "insert" "North" xy "0.75"  "0.75"  rot ""); insert north block in its place
 (setvar "osmode" oldos)
)

 

I am not sure how to (a) errase the selected north block, then (b) make the  insert north block in its place bit work

Richie
Mentor
devitg
Posts: 1,704
Registered: ‎03-14-2004
Message 2 of 7 (183 Views)

Re: Orient "north" block

09-19-2012 09:16 PM in reply to: richie.hodgson

 

(defun c:North ( /  )
(setq oldos (getvar "osmode"))
(setq blk (car (entsel "\nChoose Object:")))
(setq xy (cdr (assoc 10 (entget blk))))
(setvar "osmode" 1)
(setq rot (getangle xy "\nPlease Select End Points :"))
(setq rot (* rot (/ 180 pi)))
(setq rot (- 360 rot))
;errase block here
(command "_erase" blk "")
(setvar "osmode" 0)
(command "insert" "North" xy "0.75" "0.75" rot ""); insert north block in its place
(setvar "osmode" oldos)
)

 Try it , simple LISP 

Valued Contributor
Rtogores
Posts: 84
Registered: ‎02-07-2001
Message 3 of 7 (163 Views)

Re: Orient "north" block

09-20-2012 02:05 AM in reply to: richie.hodgson

Why don't you just rotate and if necessary translate the existing insert?

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 4 of 7 (156 Views)

Re: Orient "north" block

09-20-2012 04:56 AM in reply to: richie.hodgson

If you're putting it in the same place, you can just replace its block name and scales, and rotation if necessary:

 

(vl-load-com)

(setq blk (vlax-ename->vla-object (car (entsel "\nChoose Object: "))))

(setq rot (getangle "\nPlease Select End Points: ")); [ if necessary]

(vla-put-Name blk "North")

(vla-put-XScaleFactor blk 0.75)

(vla-put-YScaleFactor blk 0.75)

(vla-put-Rotation blk rot); [if necessary]

 

No need to convert the rotation angle to degrees, nor to involve an Insert command nor therefore to deal with object snap modes.

 

But if the idea is to replace some unwanted North Arrow block with the right one at the right size, and the wrong one is already aimed in the right direction, then there's also no need for the 'rot' variable -- it will keep its current rotation.

Kent Cooper
Mentor
richie.hodgson
Posts: 214
Registered: ‎11-05-2008
Message 5 of 7 (127 Views)

Re: Orient "north" block

09-20-2012 01:28 PM in reply to: Kent1Cooper

Hi Kent and Devig

 

Kents code worked a treat, the object was to select the orientation of the north symbol based on linework someware else on the drawing, On my PC Devig's code put the insert of the north block as the first point of the getangle code which wasn't what I wanted, not sure why it was doing this.

Richie
Mentor
devitg
Posts: 1,704
Registered: ‎03-14-2004
Message 6 of 7 (124 Views)

Re: Orient "north" block

09-20-2012 01:46 PM in reply to: richie.hodgson

Just guessing what you want to do . 

 

I can not see where the PT2 comes from . 

 

It happen because I can not see the DWG .

 

It is my fault.

 

 

 

Mentor
richie.hodgson
Posts: 214
Registered: ‎11-05-2008
Message 7 of 7 (121 Views)

Re: Orient "north" block

09-20-2012 02:10 PM in reply to: devitg

Absolutely no problem at all, solution found, problem solved. Thanks for helping

Richie
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.