Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
227 Posts
0 Kudos
Registered: ‎11-05-2008
Post 1 of 7

Orient "north" block

197 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
1,705 Posts
19 Kudos
Registered: ‎03-14-2004
Post 2 of 7

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
84 Posts
10 Kudos
Registered: ‎02-07-2001
Post 3 of 7

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*
6,043 Posts
671 Kudos
Registered: ‎09-13-2004
Post 4 of 7

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
227 Posts
0 Kudos
Registered: ‎11-05-2008
Post 5 of 7

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
1,705 Posts
19 Kudos
Registered: ‎03-14-2004
Post 6 of 7

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
227 Posts
0 Kudos
Registered: ‎11-05-2008
Post 7 of 7

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!