Jump to content

C3D 2016 LISP not working


mike3_21_21

Recommended Posts

I've just learned that some of our old LISP do not work in C3D 2016 and was looking for some help. Any help would be appreciated and here is an example of one LISP that is not working anymore.

 

(defun C:ROSNAP ()
(graphscr)
(setq oldsnap (getvar "osmode"))
(setq smd (getvar "snapmode"))
(setq tll (entsel "Select Object: "))
(setq tlle (car tll))
(setq pt1 (cadr tll))
(setq nme (cdr (assoc 0 (entget tlle))))
(if (= nme "LINE") (progn
	(setq pt2 (osnap pt1 "mid,qui"))
               (setq pt3 (osnap pt1 "end,qui"))
               (command "SNAP" "R" pt2 pt3)))
(if (= nme "POLYLINE") (progn
               (setq pt2 (osnap pt1 "mid,qui"))
               (setq pt3 (osnap pt1 "end,qui"))
               (command "SNAP" "R" pt2 pt3)))
(if (= nme "ARC") (progn
               (setq pt2 (osnap pt1 "end,qui"))
               (setq pt3 (osnap pt1 "cen,qui"))
               (command "SNAP" "R" pt2 pt3)))
(setvar "snapmode" smd)
(setvar "osmode" oldsnap)
)

Link to comment
Share on other sites

This is a known problem and you need to change COMMAND to VL-cmdf or Command-s

 

Please point me in the direction of where I can learn more about this known issue. Thanks.

Link to comment
Share on other sites

Just Google, I have to change a heap of code too. I just did around 60 in one go.

 

; this is the core so need to add findfile etc 
; Convert command to command-s
; by BIG-AL May 2015
; add rename and findfile
(defun AH:command-s (exfile / newfile fo f2)
(vl-load-com)
(setq newfile (strcat exfile ".BAK"))
(vl-file-rename exfile newfile)
(setq fo (open newfile "R"))
(setq f2 (open exfile "w"))
(while (setq str (read-line fo))
(setq str (VL-string-subst "COMMAND-S" "COMMAND" (strcase str) ))
(princ (strcat "\n" str))
(write-line str f2)
)
(close fo)
(close f2)
(princ)
)

(ah:command-s "C:/Temp/test.lsp")
; just add lots of lisps here

Edited by BIGAL
Link to comment
Share on other sites

This is a known problem and you need to change COMMAND to VL-cmdf or Command-s

 

It's not quite this simple. I've tried both and neither work for my original example in the first post.

Link to comment
Share on other sites

Command-s should work, good read: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vlisp-what-to-do-with-command-s/td-p/5058168?nobounce

What kind of error or output did you have with it?

 

I've read this with a big question mark over my head. I'd like to point out my problem is in C3D 2016.

 

In my original LISP I get this error:

Command: RoSnap Select Object: SNAP
Command: r Unknown command "R".  Press F1 for help.

 

After changing "command" to "command-s" I get this error:

Command: RoSnap Select Object: Application ERROR: Invalid type sent as command input
; error: Unknown (command-s) failure.

Link to comment
Share on other sites

While the "R" option works in 2015 it's no longer listed as an option. I haven't installed 2016 yet, have you tried at the command line to see if "Snap R " works in 2016?

Link to comment
Share on other sites

When I looked at your code I thought this is interesting method never seen rotations done this way before. You may have to rewrite to rotate an entity about a point.

Link to comment
Share on other sites

Try this:

 (defun C:ROSNAP (/ tll tlle pt1 pt2 pt3)
(graphscr)
(setq tll (entsel "Select Object: "))
(if tll (setq tlle (car tll) pt2 nil pt1 (cadr tll) nme (cdr (assoc 0 (entget tlle)))))
(cond
  ((= nme "LINE")(setq pt2 (osnap pt1 "midp") pt3 (osnap pt1 "endp")))
  ((= nme "POLYLINE")(setq pt2 (osnap pt1 "midp") pt3 (osnap pt1 "endp")))
 	  ((= nme "LWPOLYLINE")(setq pt2 (osnap pt1 "midp") pt3 (osnap pt1 "endp")))
  ((= nme "ARC")(setq pt2 (osnap pt1 "endp") pt3 (osnap pt1 "cen")))
)
(if pt2 (setvar "snapang" (- (angle pt2 pt3)pi)))
(princ)
)

Related code you may find helpful:

;| FIX CROSSHAIRS - toggles snap angle between zero & horizontal in twisted views
  BY: TOM BEAUFORD
  BeaufordT@LeonCountyFL.gov
  LEON COUNTY PUBLIC WORKS ENGINEERING SECTION

ID_SnpAng    [Toggle Snap Angle]^P(if(not C:fix)(load "fix_hair"));'fix

==================================================================|;
(defun c:fix ()
(if(= (+ (getvar "snapang")(getvar "viewtwist")) (* 2 PI))
 (setvar "snapang" 0.0)
 (setvar "snapang" (- (getvar "viewtwist")))
)
(princ)
)

Edited by tombu
Add related code
Link to comment
Share on other sites

Osmode values used in lisps may be invalidated by the addition of the new geometric center snap option.

 

His original code stored the osmode and snapmode values to reset them at the end of the code. Oddly the code never modified either one so I removed them from the modified version I posted. I don't have 2016 installed so I figured setting the snapang value rather than a command call would solve the problem.

 

Thanks for the heads up though, when I do get 2016 I'll have to check all my code for references to osmode. Bitcode 1024 has changed from "Clears all object snaps" to "Geometric CEnter". Currently bitcode 16384 is what I check for to see if osnaps are turned on, in 2016 can I assume that will be 32768?

Link to comment
Share on other sites

When I looked at your code I thought this is interesting method never seen rotations done this way before. You may have to rewrite to rotate an entity about a point.

 

I can't take credit for this code. It was written years ago before I started working here in '99.

Link to comment
Share on other sites

His original code stored the osmode and snapmode values to reset them at the end of the code. Oddly the code never modified either one so I removed them from the modified version I posted. I don't have 2016 installed so I figured setting the snapang value rather than a command call would solve the problem.

 

Thanks for the heads up though, when I do get 2016 I'll have to check all my code for references to osmode. Bitcode 1024 has changed from "Clears all object snaps" to "Geometric CEnter". Currently bitcode 16384 is what I check for to see if osnaps are turned on, in 2016 can I assume that will be 32768?

 

I'm not sure if they ever worked to be honest. This LISP was written long before I ever started working here in '99.

Link to comment
Share on other sites

I'm not sure if they ever worked to be honest. This LISP was written long before I ever started working here in '99.

 

It worked for a line in 2015. LWPOLYLINE's were introduced in r14 back in 1997. Since they weren't addressed in the code and the "R" Snap option hasn't been listed in help since about that time the code was pretty dated. Did the modified ROSNAP I posted work ok? With Civil/Survey drawing twisted views are the norm so I have a few related macros and routines.

Link to comment
Share on other sites

It worked for a line in 2015. LWPOLYLINE's were introduced in r14 back in 1997. Since they weren't addressed in the code and the "R" Snap option hasn't been listed in help since about that time the code was pretty dated. Did the modified ROSNAP I posted work ok? With Civil/Survey drawing twisted views are the norm so I have a few related macros and routines.

 

Yes it works. THANKS. Not the answer I was truly looking for, because I got a few others with "command" in them not working. I'll post here and see what you all think.

Link to comment
Share on other sites

Here are just three. I don't want to over stay my welcome here. Now if anyone wants to play I'll upload the whole thing. Heck, I might. Thanks again.

 

(defun C:SPLIT ()
(graphscr)
(setq oldsnap (getvar "osmode"))
(setq os (getvar "osmode"))
(setvar "osmode" 1536)
(setq l1 (getpoint "\nSelect line to be Split: "))
(setq l2 (getpoint "\nSelect Cutting Edge: "))
(setvar "osmode" os)
(setq pt1 (osnap l1 "mid,qui"))
(setq pt2 (osnap l1 "end,qui"))
(setq pt3 (osnap l2 "mid,qui"))
(setq pt4 (osnap l2 "end,qui"))
(setq pt5 (inters pt1 pt2 pt3 pt4 nil))
(command "BREAK" l1 "F" pt5 "@")
(setvar "osmode" oldsnap)
)

(defun C:ARROW ()
(graphscr)
 	(setq oldsnap (getvar "osmode"))
(setq player (getvar "clayer"))
(setq tll (entsel "Pick Point on Line Nearest End:"))
(setq pt1 (cadr tll))
(setq tlle (car tll))
(setq layn (cdr (assoc '8 (entget tlle))))
(setq pt2 (osnap pt1 "end,qui"))
(setq pt3 (osnap pt1 "nea,qui"))
  	(setq size (getvar "dimscale"))
(command "LAYER" "S" layn "")
(command "INSERT" "ARROWHD" pt2 size "" pt3)
(command "layer" "s" player "")
(setvar "osmode" oldsnap)
(setvar "clayer" oldlayer)
)

(defun C:AUTODIM1 ()
(graphscr)
(setq oldsnap (getvar "osmode"))
(setq oldlayer (getvar "clayer"))
(command "-layer" "s" "PR-2-NOTES" "")
(setq rnd (getvar "dimzin"))
(setq acr (getvar "luprec"))
(setq obj1 (entsel "\nSelect Line to Dimension Above: "))
(setq obj2 (car obj1))
(setq pt1 (cdr (assoc '10 (entget obj2))))
(setq pt2 (cdr (assoc '11 (entget obj2))))
(setvar "dimzin" 
(setq dist (distance pt1 pt2))
(setq txt1 (rtos dist 2 acr))
(setq txt2 (strcat txt1 (chr 039)))
(setq pt3 (cadr obj1))
(setq pt4 (osnap pt3 "mid,qui"))
(setq pt5 (osnap pt3 "nea,qui"))
(setq angler (angle pt4 pt5))
(setq angled (/ (* 180 angler) pi))
(setq perpr (+ angler (/ pi 2)))
(setq centerpt (polar pt4 perpr (/ (getvar "dimscale") 16)))
(setvar "dimzin" rnd)
(command "TEXT" "C" centerpt angled txt2)
(setvar "osmode" oldsnap)
(setvar "clayer" oldlayer)
)

Link to comment
Share on other sites

A co-worker of mine just noticed ",qui" in our codes. We took them out and things seem to be working. I sure like simple fixes.

Link to comment
Share on other sites

A co-worker of mine just noticed ",qui" in our codes. We took them out and things seem to be working. I sure like simple fixes.

 

The qui or quick option for the osnap command is described in 2015 Help, but not 2016 Help. Guess they finally dropped it, never saw a use for it anyway.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...