Osnap does not work inside subroutines

Osnap does not work inside subroutines

greglcroth
Contributor Contributor
1,285 Views
13 Replies
Message 1 of 14

Osnap does not work inside subroutines

greglcroth
Contributor
Contributor

I'm trying to automate insertion of blocks for a Custom "Feild to Finshing" program.   The idea here is to zoom to the insert point, and allow the user to rotate the block or connect to another object.  Here, the user picks the power pole to draw the guy wire to.  My main routine looks at survey point blocks descriptions runs several codes like:

 

(if (= DESC "GUY")
  (progn
    (load "GUY.lsp")
    (command "zoom" "c" coords ZOOMLEV)
    (command "GUY" coords PAUSE)
  )
)

 

So that part feeds coordiates to "Guy.Lsp" then waits for the user input --picking the power pole to connect the guy wire to.

 

GUY.LSP is...

 

(defun C:GUY (/ GUYEND POWP SCALE )
  (graphscr)
  (setq SCALE (getvar "DIMSCALE"))
  (command "layer" "set" "U-POLE" "")
  (command "osnap" "node")
  (prompt "\nOsnap is now set to NODE")
  (setq GUYEND (getpoint "\nStarting point for guy wire, away from power pole: "))
  (SETQ guyend (LIST (CAR guyend) (CADR guyend) 0.0))
  (command "osnap" "NODE")                                                                             ;;; <<<------- DOESN'T WORK
  (setq POWP (getpoint GUYEND "\nSelect the center of the power pole: "))
  (SETQ powp (LIST (CAR powp) (CADR powp) 0.0))
  (command "osnap" "none")
  (command "insert" "GUY" GUYEND SCALE "" POWP)
  (command "line" GUYEND POWP "")
  (command "osnap" "none")
  (princ) ; end guy.lsp
)

 

Everything works except the OSNAP settings in "GUY.LSP" don't turn on/off.

 

Is there some setting I need to trip to make Osnaps work inside subroutines called by other routines?

 

 

 

0 Likes
Accepted solutions (1)
1,286 Views
13 Replies
Replies (13)
Message 2 of 14

komondormrex
Mentor
Mentor

try to get node point like this

(setq GUYEND (osnap (getpoint "\nStarting point for guy wire, away from power pole: ") "_nod"))

and snap to none like this

(command "insert" "GUY" "_non" GUYEND SCALE "" POWP)

 and this

(command "line" "_non" GUYEND "_non" POWP "")
0 Likes
Message 3 of 14

paullimapa
Mentor
Mentor
Accepted solution

Just a shot in the dark here. What if instead of using command to change osnap, you used setvar 

(setvar 'osmode 8) ;;sets the osnap mode to node

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 14

greglcroth
Contributor
Contributor

Using ....

(setvar 'osmode 8) instead of (command "osnap" "NODE")

... worked for me.  Not sure why one works but not the other.  

 

FWIW, the method komondormrex  suggested didn't work.  Again, I don't know why.  Seems like all three methods should work, I have to assume it's some weird problem around calling a LISP within a LISP.  Should have mentioned, Guy.LSP is also a "stand alone" function that works fine otherwise.

 

But thank you both for the help.

0 Likes
Message 5 of 14

paullimapa
Mentor
Mentor

Glad at least one of the options worked out for you …cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@greglcroth wrote:

....

  (command "osnap" "node")
  (prompt "\nOsnap is now set to NODE")
  (setq GUYEND (getpoint "\nStarting point for guy wire, away from power pole: "))
  (SETQ guyend (LIST (CAR guyend) (CADR guyend) 0.0))
  (command "osnap" "NODE")              ;;; <<<------- DOESN'T WORK
  ....


Why twice, without anything changing to some other mode(s) in between?  Since you mark the second one as not working, does the first one work?

 

On the question of why the (setvar) method works but the (command) method doesn't:  Might you have some redefinition of the Osnap command going?  Are there any messages when it "doesn't work"?  Does it work if you force it to use the native command, with a period prefix?

(command ".osnap" "node")

Kent Cooper, AIA
0 Likes
Message 7 of 14

greglcroth
Contributor
Contributor

Kent, you are right, there are probably a lot of redundant commands in there.  I made dozens of these by modifying a "template" LISP ... in some cases that second to third reset of snap may be to perp or end, or some other option depending on the block being inserted, but it could definitely use some cleaning up.  These were initially meant to be stand alone LISPs, for drafting, and still can be used that way, but the first snap setting is not really needed when I run it automated.  

 

As for your suggestion, I tried it, and .snap doesn't work either when called from the main LISP.  

 

But I can then immediately type "GUY" at the command prompt, and the snaps do work when run I run by itself ... no idea why.

0 Likes
Message 8 of 14

Automohan
Advocate
Advocate

Snap.png

My osmode is set to "0"

when I type whatever i need in that time it works !

Example: "end of"  "nea of"  "nod of"  "mid of"  whatever you type (when my osmode is 0)

 

But not works with route.

 

(setvar "osmode" 0)
(setq pt1 (osnap (getpoint "\nPick your second point: ") "_nea"))
(setq pt2 (osnap (getpoint "\nPick your third point: ") "_end"))

 

Any system variable issue ?

Please post your system variables related to snap if you don't mind.

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

[I don't see why that is in Reply to me, but in any case....]

It works for me.  Can you describe the issue in more detail?

Kent Cooper, AIA
0 Likes
Message 10 of 14

Automohan
Advocate
Advocate

I generate my custom rotate route !

(defun c:myrota ( / *error* old_osmode pt1 pt2 pt3 pt4 pt5 sg )
      
(defun *error* (errmsg)
   (setvar "osmode" old_osmode)
  (if (not (member errmsg '("Console Break" "Function cancelled" "*Cancel*")))
    (princ (strcat "\nError: " errmsg))))
      
(setvar "cmdecho" 0)
(setq old_osmode (getvar "OSMODE"))
(setvar "osmode" 0)
(setq sg (ssget))
(setq pt1 (osnap (getpoint "\nPick your base point: ") "_end,_nod"))
(setq pt2 (osnap (getpoint "\nPick your first point: ") "_nea"))
(setq pt3 (osnap (getpoint "\nPick your second point: ") "_nea"))
(setq pt4 (osnap (getpoint "\nPick your third point: ") "_end"))
(setq pt5 (osnap (getpoint "\nPick your third point: ") "_end"))
   (command "rotate" sg "" pt1 "r" pt2 pt3 "P" pt4 pt5)
(setvar "cmdecho" 1)
(setvar "OSMODE" old_osmode) (princ))

My system variable settings as below

Drafting.png User Pre.png

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

Again, it works for me -- resulting point variables are at NEArest and ENDpoint locations as expected.  Please explain in more detail what you mean by "not works" -- what happens, what doesn't happen, in what way is what happens different from what you expect?  Etc., etc.

 

Also, I suggest that you include a resetting of CMDECHO in the *error* handler, as you do for OSMODE.

 

[By the way, "route" is an English word, but it means something entirely different.  The word you want is "routine."]

Kent Cooper, AIA
0 Likes
Message 12 of 14

ВeekeeCZ
Consultant
Consultant

My preferred way is to set osmode directly. That gives you a chance to change it during command if needed by temp overrides.

The second routine gives you the same prompt as you have.

The OSNAP lisp function does not work interactively - if that's what you want.

 

 

(defun c:myrota ( / *error* old_osmode pt1 pt2 pt3 pt4 pt5 sg )
  
  (defun *error* (errmsg)
    (setvar "osmode" old_osmode)
    (if (not (member errmsg '("Console Break" "Function cancelled" "*Cancel*")))
      (princ (strcat "\nError: " errmsg)))
    (if old_osmode (setvar "OSMODE" old_osmode))
    (setvar 'cmdecho 1))
  
  (setvar "cmdecho" 0)
  (setq old_osmode (getvar "OSMODE"))
  (setq sg (ssget))
  (setvar "osmode" (+ 1 8))
  (setq pt1 (getpoint "\nPick your base point: "))
  (setvar "osmode" (+ 512))
  (setq pt2 (getpoint "\nPick your first point: "))
  (setq pt3 (getpoint "\nPick your second point: "))
  (setvar "osmode" (+ 1))
  (setq pt4 (getpoint "\nPick your third point: "))
  (setq pt5 (getpoint "\nPick your third point: "))
  (setvar "osmode" 0)
  (command "rotate" sg "" pt1 "r" pt2 pt3 "P" pt4 pt5)
  (setvar "cmdecho" 1)
  (setvar "OSMODE" old_osmode) (princ))


(defun c:yourrota ()
  (if (setq sg (ssget "_:L"))
    (command "rotate" sg "" "_end,_nod" pause "_r" "_nea" pause "_nea" pause "P" "_end" pause "_end" pause))
  (princ)
  )

 

0 Likes
Message 13 of 14

Automohan
Advocate
Advocate

When I run the 2nd routine

 

(defun c:yourrota ()
  (if (setq sg (ssget "_:L"))
    (command "rotate" sg "" "_end,_nod" pause "_r" "_nea" pause "_nea" pause "P" "_end" pause "_end" pause))
  (princ))

 

all those snaps  "_end,_nod"    "_nea"   "_end"  works with (setvar "osmode" 0), fantastic

 

but Kent1Cooper sounds below routine works for him

 

(setvar "osmode" 0)
(setq pt1 (osnap (getpoint "\nPick your second point: ") "_nea"))

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 14 of 14

ВeekeeCZ
Consultant
Consultant

@Automohan wrote:

...

but Kent1Cooper sounds below routine works for him

 

(setvar "osmode" 0)
(setq pt1 (osnap (getpoint "\nPick your second point: ") "_nea"))

 


 

 

Easy, man. Of course, it works. For me, too. Just the way it's designed to, not the way you imagined. 

Think of how it works, what is evaluated first, what later. And how possibly can a subsequent function affect the previous one.

0 Likes