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

Trouble with a script using AutoLISP & WBLOCK

9 REPLIES 9
Reply
Message 1 of 10
lfrost
529 Views, 9 Replies

Trouble with a script using AutoLISP & WBLOCK

Hello All,

 

I'm hoping someone can tell me what I'm doing wrong in the code below; I feel like it is something silly that I'm just not catching:

 

(defun HAPPY ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq sspoly (ssget "A" '((0 . "LWPOLYLINE"))))
(setq sscirc (ssget "A" '((0 . "CIRCLE"))))
(setq ssline (ssget "A" '((0 . "LINE"))))
(setq enpoly (ssname sspoly 0))
(setq enpoly (entget enpoly))
(setq enpoly (assoc 10 enpoly))
(setq pt (list (cadr enpoly) (caddr enpoly)))
(setq filename (getvar "dwgname"))
(setq file (strcat "S:/1. Design Assist/2112 PENN AVENUE/0.1 LBFs Experimental Folder/Outputs/" filename))
(command "wblock" file "" pt "all" "")
(setvar "CMDECHO" cmdecho)
)
(setvar "tilemode" 1)
(command "layer" "set" "FIN PATTERNS" "OFF" "*" "n" "FREEZE" "*" "THAW" "DIM" "ON" "DIM")
(command)
(HAPPY)

 

I got this code (and script) to work last week in a SCRIPT (.scr) to block out a bunch of different pattern glass fab tickets, but now it doesn't work.  ScriptPro says "DONE", but when I run the script in an individual drawing... The WBLOCK line spits out a nil and the objects that should be blocked out remain in the drawing.

 

To be clear, it functions perfect as a LISP routine.  However, it does not complete the WBLOCK line when I import into a SCRIPT.  Also, there are no files in the target folder (WBLOCK command won't spit out the "Do you wish to replace" dialog.  I will eventually add a couple vl lines to automatically delete the file before the WBLOCK to prevent the message from appearing.

 

 

Thanks in advance everyone.  This is really frustrating me.

Frost

9 REPLIES 9
Message 2 of 10
paullimapa
in reply to: lfrost

Since you have spaces in the folder name, perhaps try surrounding the file name with quotes:

 

(setq file (strcat "\"S:/1. Design Assist/2112 PENN AVENUE/0.1 LBFs Experimental Folder/Outputs/" filename "\""))

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 10
lfrost
in reply to: paullimapa

Thanks Paul, but unfortunately it still does not work.  When I run the script, the variables and my defined function HAPPY are not processed.  After I run the script on one file (using the command SCRIPT, not ScriptPro), HAPPY is not defined; which means the variables and selection sets are not defined either.

 

What am I overlooking?  This is driving me nuts that it's not working all of the sudden.

Message 4 of 10
paullimapa
in reply to: lfrost

What if you save the lisp code into a file called HAPPY.lsp

Then in the Script file use the following line to load the script file:

(load"HAPPY")

 

Then activate the function with this line:

(HAPPY)

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 10
lfrost
in reply to: paullimapa

Paul... Thank you!  Success!

 

I was trying every work around in the book trying to get it to work, but that is the one I needed.  Thank you my friend.

Message 6 of 10
paullimapa
in reply to: lfrost

Message 7 of 10
lfrost
in reply to: paullimapa

Well... Just found out that it hasn't exactly.  When I run the script in AutoCAD, it's fine.  But, when I use it in ScriptPro... It says it's "Done," but it didn't save the changes.  I added a qsave to the end of the script and no luck.

 

Why is my ScriptPro acting like this?  Shouldn't it read the script file the same way?

Message 8 of 10
paullimapa
in reply to: lfrost

Hopefully someone with ScriptPro experience can chime in here...

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 10
Kent1Cooper
in reply to: lfrost

Maybe it's only a copy/paste glitch, and your file as applied doesn't have this problem, but I don't see a closing right parenthesis for the (defun) function in the code in the first message.  It looks like it ought to have one after the last (command) function and before the (HAPPY) that invokes what was just defined, but what it was trying to define won't be without closing the defining function.

 

[EDIT -- Never mind; I see it farther up.  I was figuring the stuff near the bottom was part of the function definition, but apparently not.  I thought deleting my Reply would be one of my Options, but at the moment it's not offering that....]

Kent Cooper, AIA
Message 10 of 10
lfrost
in reply to: Kent1Cooper

Thanks for the reply Kent, but I think you may have missed the closing bracket just a few lines higher (see bold & italiced below):

 

(defun HAPPY ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq sspoly (ssget "A" '((0 . "LWPOLYLINE"))))
(setq sscirc (ssget "A" '((0 . "CIRCLE"))))
(setq ssline (ssget "A" '((0 . "LINE"))))
(setq enpoly (ssname sspoly 0))
(setq enpoly (entget enpoly))
(setq enpoly (assoc 10 enpoly))
(setq pt (list (cadr enpoly) (caddr enpoly)))
(setq filename (getvar "dwgname"))
(setq file (strcat "S:/1. Design Assist/2112 PENN AVENUE/0.1 LBFs Experimental Folder/Outputs/" filename))
(command "wblock" file "" pt "all" "")
(setvar "CMDECHO" cmdecho)
)
(setvar "tilemode" 1)
(command "layer" "set" "FIN PATTERNS" "OFF" "*" "n" "FREEZE" "*" "THAW" "DIM" "ON" "DIM")
(command)
(HAPPY)

 

I'm going to try to run it on my desktop at home, maybe something is faulty in the software?  Using Paul's suggestion, the script works, but does not save.  Maybe it's still not processing the AutoLISP codes within the commands?  Any chance this is an AutoCAD variable that got changed?

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

Post to forums  

Autodesk Design & Make Report

”Boost