Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
Posts: 187
Registered: ‎11-05-2008
Message 1 of 7 (174 Views)

Orient "north" block

174 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
Posts: 1,682
Registered: ‎03-14-2004
Message 2 of 7 (169 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
Posts: 84
Registered: ‎02-07-2001
Message 3 of 7 (149 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: 4,982
Registered: ‎09-13-2004
Message 4 of 7 (142 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
Distinguished Contributor
Posts: 187
Registered: ‎11-05-2008
Message 5 of 7 (113 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
Posts: 1,682
Registered: ‎03-14-2004
Message 6 of 7 (110 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.

 

 

 

Distinguished Contributor
Posts: 187
Registered: ‎11-05-2008
Message 7 of 7 (107 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community