Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Xof & Yof Custom Snaps - How to "initialize" properly?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
process_solutions
798 Views, 9 Replies

Xof & Yof Custom Snaps - How to "initialize" properly?

I have created some custom OSNAPs and have them defined for transparent invokation by not having the LISP routines make use of the (Command ""....."") LISP expression & have them in my OSNAP shortcut menu.

 

As defined in my Autoload:

;XOF - USER NEEDS ONLY SPECIFY X COORDINATE

(defun C:XOF ()
(load "XOF")
(C:XOF)
(princ)
)

 

;YOF - USER NEEDS ONLY SPECIFY Y COORDINATE
(defun C:YOF ()
(load "YOF")
(C:YOF)
(princ)
)

 

 

Then as individual LISP functions:

(Defun C:XOF ( / Userpikpt xcoordnate yzcoordnate finalcoordnate)
(prompt "\nPick X Coordinate...")
(setq yzcoordnate (cdr (getvar "LASTPOINT")))
(setq userpikpt (getpoint))
(setvar "OSMODE" 0)
(setq finalcoordnate (append (list  (car userpikpt)) yzcoordnate))
finalcoordnate
);END DEFUN

 

(Defun C:YOF ( / Userpikpt xzcoordnate finalcoordnate)
(prompt "\nPick Y Coordinate (Z coordinate will be 0.0)...")
(setq xzcoordnate (car (getvar "LASTPOINT")))
(setq userpikpt (getpoint))
;GET THE Y FROM THE USER PICK POINT
(setvar "OSMODE" 0)
(setq the_y_point(car (cdr userpikpt)))
(setq finalcoordnate (list  xzcoordnate the_y_point 0.0))
finalcoordnate
);END DEFUN

 

They work like a charm ONCE THEY HAVE ALREADY BEEN USED ONCE.  What I have to do, is upon starting my AutoCAD session for the first time, I type Xof <ENTER><ENTER> & then YOF <ENTER><ENTER> & the snaps will work like a charm for the rest of the session (usually my whole workday).

 

If I have not yet used them (or forgot to invoke them from the command line right from the beginning as I just described) they for some reason (I am stumped thus the post), they do not function & I have to cancel the command or re-issue the snap request of Xof or Yof... & upon second & all subsequent uses, the Xof & Yof snaps work great.

 

Is there a way to have AutoCAD automatically "Prime" these functions or to improve the functions themselves so that thay do not need to be "primed"?

 

I hope someone has an answer & otherwise I am sharing my groovy snaps - They work great for Electrical Schematic work, Diagrams etc.. especially when you are stretching geometry to match other geometry.

 

Regards,

Sean

9 REPLIES 9
Message 2 of 10
stevor
in reply to: process_solutions

This is the simplest form; you can use the subroutine, or take parts from it. [code] ; get point w default-pt, prompt-str (defun get_p (dp ps / ans ) (graphscr) (setq ans (if dp (getpoint dp (strcat ps ", default: ")) (getpoint ps)) ) (if ans ans dp) ) [code]
S
Message 3 of 10

I'm trying to figure out whether these are fundamentally any different than AutoCAD's built-in .X and .Y coordinate filters [and all the other possibilities: .Z and .XY and .XZ and .YZ].

Kent Cooper, AIA
Message 4 of 10

They are different only in that only 1 pick point is necessary when selecting a final coordinate.  Rather than selecting for a filter then specifying the remainder of the coordinate, the remainder of the coordinate is inferred from LASTPOINT which is usually established when you specify a base point.

Example:

Command: Move

Select objects: Specify opposite corner: 1 found

Select objects:
Specify base point or [Displacement] <Displacement>: (User makes first pick & establishes LASTPOINT)

Specify second point or <use first point as displacement>: 'Xof (User makes only a single pick instead of specifying filter then picking or typing "@"<ENTER>)

Pick X Coordinate...(13.994 12.0491 0.0) <--the coordinate is passed to Move command...

[ACTION EXECUTED w/o need for multiple specifications for point filter]

 

Works great & much faster than using point filters.  🙂

Message 5 of 10
process_solutions
in reply to: stevor

How would the expressions I currently have be modified to inegrate the logic you are suggesting so as to "prime" the functions I am trying to use? I am at a bit of a loss to interpret the code you provide as to equate it to a solution to the expressions I am currently using.  Can you propose a modification to the existing logic I already have vs providing some other logic which I am sorry I am not sure how to use lol?

 

Thank you for your reply as it does make me think alternatively about how to acquire user input.

 

Regards,

Sean

Message 6 of 10


@process_solutions wrote:

They are different only in that only 1 pick point is necessary when selecting a final coordinate.  Rather than selecting for a filter then specifying the remainder of the coordinate, the remainder of the coordinate is inferred from LASTPOINT which is usually established when you specify a base point.

....


Yeah....  In the interim, I managed to realize that advantage.

 

I wonder whether the "priming" problem might have anything to do with the fact that you have a command defined that loads a file that contains and calls up a different definition of a command with the same name, within the running of the other definition of that command name.  I don't know, maybe it's valid, but that kind of recursiveness always makes me nervous.

 

If you're having things loaded automatically anyway, maybe you should just load the full routines instead of the ones that call for loading them [they're not all that much longer, and not much of a "load" on AutoCAD], and skip the middle-man.  Or, you could try this:

 

Combined into one Lisp file called XYOF.lsp:

 

(defun C:XOF ....

)

(defun C:YOF ...

)

 

Then, in acaddoc.lsp or some place:

 

(autoload "XYOF" '("XOF" "YOF"))

 

Then it still won't load the file at all unless and until one of those commands is called for.  And since there's no possible conflict in command names, it should get around your initial problem, if that conflict has anything to do with it.

Kent Cooper, AIA
Message 7 of 10

Thank you VERY much good sir for your excellent solution.

 

On my wishlist for this is how have the invocation of this not only pass the coordinate to the active command, but to then also restore the OSMODE to whatever it was before Xof or Yof was invoked.  As it stands now, I just have to toggle my osnap using another function I have added to my OSNAP menu called simply enough "Q" for QuickSnap toggle... which forces the value to 1127 if not already 1127 or to 0 if it is alredy 1127.

 

(defun c:Q ()
(if (/= (getvar "osmode") 1127)
(setvar "osmode" 1127)
(setvar "osmode" 0)
)
(princ)
)

 

There may not be a way to do this without creating an Xof/Yof accomodating variant of the native AutoCAD command, but I post it just in case anyone has the answer.

 

Shared TIP for any who read this thread:

I edited my OSNAP menu so as to put at both the top & bottom of the menu my "Q" & "Xof" & "Yof" commands so that no matter where the mouse is on the screen, these "snap accellerators" as will call them are right there where the mouse is so it is almost never necessary to  remove my hand from the keyboard or mouse when seeking fast snaps or to toggle useful snap control.  This OSNAP stratedy nearly doubles editing speed where coordinate entry is concerned.

 

Cheers & Many Thanks,

Sean @ Process Solutions, Inc.

 

Message 8 of 10


@process_solutions wrote:

I have created some custom OSNAPs and have them defined for transparent invokation .... 

....I am sharing my groovy snaps - They work great for Electrical Schematic work, Diagrams etc.. especially when you are stretching geometry to match other geometry.

....


They are kind of groovy, after all, though I noticed a few things....

 

It's not necessary to save the final coordinates to a variable and then call that variable for the function to feed the result out to AutoCAD.  The return from a (defun) is the last thing that happens in it, so if that's the calculation of the final coordinates, you can just let the calculation feed its result out, and forget the variable.

 

It doesn't seem desirable [to me, anyway], and it's certainly not necessary, to restrict YOF to using 0 for the end-result Z coordinate.  What if you were drawing a Line from some place with a non-zero Z, and you wanted the next endpoint to use that Z coordinate, just as it does the X coordinate, from the previous point?

 

Setting OSMODE to 0 turns object snap really OFF off, dumping your current combination of modes.  But it's possible to have the routine check whether running Osnap is on, and if so, do the equivalent of hitting F3, that is, turn off the running aspect, but keep the combination of modes you have set.  Then you can restore that just by hitting F3, and don't need to pick them all from the dialog box again.  That seems especially important in this situation, where Osnap needs to be left not running [at least, I couldn't figure out a way to turn it back on under the circumstances, since that would need to happen after the routine has ended and fed its results out to whatever command is running].

 

You can shortcut (car (cdr ...)) by using (cadr ...) to get the second item in a list [the Y coordinate of a point].

 

And I figured there might as well be versions available for the other coordinate possibilities that AutoCAD's coordinate filters offer: Z, XY, XZ, YZ.

 

So I put together the attached.  I used NX, NY, etc. as command names, the N being for the Next coordinate(s), since it seemed more apparent [to me] that way that it's always working in relation to the previous point, and not "out of the blue" as AutoCAD's coordinate filters do.  [Besides, it's one less letter to type!]  And the prompts contain a reminder that other coordinates will be the same as the previous point (@).  I also consolidated repetitive elements into sub-routines.

 

I have added this line to my acaddoc.lsp file, to make them all available, but to not load the file unless and until one of the commands is called for:

 

(autoload "NextXYZCoord" '("NX" "NY" "NZ" "NXY" "NXZ" "NYZ"))

Kent Cooper, AIA
Message 9 of 10


@process_solutions wrote:

Thank you VERY much good sir for your excellent solution.

 

On my wishlist for this is how have the invocation of this not only pass the coordinate to the active command, but to then also restore the OSMODE to whatever it was before Xof or Yof was invoked.  ....


[Looks like yours arrived while I was writing mine....]

 

I agree -- that would be preferable.  See my NextXYZCoord.lsp attached to my previous post for a way to at least make your prior Osnap mode combination, whatever it is, restorable by just hitting F3, rather than using a menu item that sets it to a predetermined combination that might be different from what you had going.

 

I tried several ways to do what you're asking, by leaving Osnap on and trying to override it in the return of the function.  One was to use the (osnap) function on the calculation of the final coordinates:

 

(osnap (...final coordinates...) "_none")

 

But though that will determine a point ignoring any running Osnap modes, once the end of the (defun) is reached, and it feeds that point out to the command that's running, if Osnap is on, it still applies it to that result.  The same is true with the other approach I tried, which was to define them as functions, not commands, and then they can be "transparent" even if you use the (command) function in them, so I was hoping to use that to feed the final coordinates out to the surrounding command:

 

(defun NX (...); <-- without the C:

  ....

  (command (osnap (...final coordinates...) "_none"))

)

 

They would need to be invoked in parentheses, rather than with leading apostrophes -- (NX).  But unfortunately, that has the same problem that the (defun C:NX ...) approach has.

 

And you can't reset OSMODE inside the routine at the end, because that number is what will be fed out to the surrounding command, not the coordinates that have been calculated.

 

If I think of some other approach, and find it works, I'll surely post it here.

 

Edited:  HERE IT IS!  I was doing the (command) feed-out thing wrong; this approach works:

 

  (command "_none" (...final coordinates...))

 

The attached uses that approach.  The functions need to be used with parentheses, but if you're putting them in menu items/toolbar buttons, that shouldn't matter.

Kent Cooper, AIA
Message 10 of 10

To load this super-duper improved version you so excellently composed - I played around with some expressions in my "Utility2010.lsp" file which is invoked by acaddoc.lsp for loading all my stuff & settled on:


(Defun Load_Custom_Snaps ()
(load "NextXYZCoord")
(princ)
)


& the last portion of that lsp file:


(defun-q S::STARTUP ()
(Load_Custom_Snaps)
...other prompts n such to greet the CAD operator

...

)


Many thanks & I hope others get as much mileage/use as I certainly will.


Cheers,

Sean

 

EDIT:

"Assembly file name:"
"Command: COMMANDLINE"

 

Pops up when I try to autoload... I will try to put them directly in my acaddoc.lsp but hate to have anything in that file versus just in my proprietary lsp defun file.  Still trying to get a clean/transparent autoload for this but I really do like it.

 

-Sean

 

EDIT AGAIN:

I simply load it with my main defun lsp file with all my custom content

(load "NextXYZCoord")

 

Many thanks & I look forward to using this forum in the future.  As I mention above, I hope others find this a useful final-coordinate snap option.

 

Regards,

Sean

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost