jubi23 Posted September 24, 2009 Posted September 24, 2009 Hey, new to the community, although slightly experienced with VBA, autolisp cuis etc... sorry if my whole rant here sounds a bit confusing I found someone that had a similar problem to my own, but no solution. http://www.cadtutor.net/forum/showthread.php?t=40367 I have a pretty simple script that sets up some parameters and then inserts a block, it's been working for years but on this one drawing it get's to the insert of the block, asks for x scale, and repeats whatever command i did before i used my toolbar lisp command. If i open up a new drawing or any other drawing that's been worked on, the insertion works fine, but in this one drawing it won't, and i could just start the drawing over, but it's driving me mad! you can see below a copy of my command prompt and where it tries to do my last command (that being line) if anyone has ideas please let me know Command: (load "05-02-03") ortho Enter mode [ON/OFF] : on Command: Enter New, Existing, Demolition, or Future? [NEW]n -layer Current layer: "T-Data-Devc-Wall-N" Enter an option [?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/PStyle/Freeze/Thaw/LOck /Unlock/stAte]: s Enter layer name to make current or : T-Data-Devc-Wall-N Enter an option [?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/PStyle/Freeze/Thaw/LOck /Unlock/stAte]: Command: Insertion Point insert Enter block name or [?]: 05-02-03-NW.dwg Units: Inches Conversion: 0'-1" Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]: Enter X scale factor, specify opposite corner, or [Corner/XYZ] : Command: LINE Specify first point: nil Specify first point: *Cancel* ;Wall-Mounted Data Devices ;A.ARNONE ;UPDATED (7.11.06) ;start variable definition (setq usr3 (* (getvar "userr3"))) (if (= usr3 3600.0) (setq r3 50)) (if (= usr3 2400.0) (setq r3 25)) (if (= usr3 1200.0) (setq r3 12.5)) (IF (= USR3 600.0) (setq r3 6.25)) (if (= usr3 480.0) (setq r3 5)) (if (= usr3 360.0) (setq r3 3.75)) (if (= usr3 240.0) (setq r3 2.5)) (if (= usr3 120.0) (setq r3 1.25)) (IF (= USR3 384.0) (SETQ r3 4)) (IF (= USR3 192.0) (SETQ r3 2)) (IF (= USR3 128.0) (SETQ r3 1.33333333333)) (IF (= USR3 96.0) (SETQ r3 1)) (IF (= USR3 64.0) (SETQ r3 0.666666666667)) (IF (= USR3 48.0) (SETQ r3 0.5)) (IF (= USR3 32.0) (SETQ r3 0.333333333333)) (IF (= USR3 24.0) (SETQ r3 0.25)) (IF (= USR3 16.0) (SETQ r3 0.166666666667)) (IF (= USR3 12.0) (SETQ r3 0.125)) (IF (= USR3 8.0) (SETQ r3 0.083333333333)) (IF (= USR3 4.0) (SETQ r3 0.041666666667)) (IF (= USR3 2.0) (SETQ r3 0.020833333333)) (IF (= USR3 1.0) (SETQ r3 0.010416666667)) (IF (= USR3 0) (SETQ r3 1)) (setq newlayer "T-Data-Devc-Wall-N") (setq newlayercolor "3") (setq newlayerlineweight "0.50") (setq newlayerlinetype "Continuous") (setq newlayerplotstyle "Black") (setq lookupnew (tblsearch "LAYER" newlayer)) (setq atriblocknw "05-02-03-NW.dwg") ;end variable definition (command "ortho" "on") ;Sets Working Layer (setq workinglayer (GETSTRING "Enter <N> New, <E> Existing, <D> Demolition, or <F> Future? [NEW]")) (terpri) (cond ((= workinglayer "N") ;checks and/or defines layer to draw on (if (= lookupnew nil) (command "-layer" "n" newlayer "s" newlayer "C" newlayercolor "" "L" newlayerlinetype "" "Lw" newlayerlineweight "" "PS" newlayerplotstyle "" "") (command "-layer" "s" newlayer "") ); END IF ;Sets P1 TO start point of Receptacle and Inserts Block (prompt "Insertion Point") (terpri) (setq p1 (getpoint)) (command "insert" atriblocknw p1 r3 "") ) ((= workinglayer "n") ;checks and/or defines layer to draw on (if (= lookupnew nil) (command "-layer" "n" newlayer "s" newlayer "C" newlayercolor "" "L" newlayerlinetype "" "Lw" newlayerlineweight "" "PS" newlayerplotstyle "" "") (command "-layer" "s" newlayer "") ); END IF ;Sets P1 TO start point of Receptacle and Inserts Block (prompt "Insertion Point") (terpri) (setq p1 (getpoint)) (command "insert" atriblocknw p1 r3 "") ) ((= workinglayer "") ;checks and/or defines layer to draw on (if (= lookupnew nil) (command "-layer" "n" newlayer "s" newlayer "C" newlayercolor "" "L" newlayerlinetype "" "Lw" newlayerlineweight "" "PS" newlayerplotstyle "" "") (command "-layer" "s" newlayer "") ); END IF ;Sets P1 TO start point of Receptacle and Inserts Block (prompt "Insertion Point") (terpri) (setq p1 (getpoint)) (command "insert" atriblocknw p1 r3 "") ) );end condition Quote
SteveK Posted September 24, 2009 Posted September 24, 2009 Hello, welcome to the forum. Because your problem is only happening in one drawing I am just wondering if you type in the command prompt (getvar "userr3") is the output equal to one of the if statements up the top of your code? Also, just to make things clearer I've updated your code from ;Sets Working Layer here. ;Wall-Mounted Data Devices ;A.ARNONE ;UPDATED (7.11.06) ;start variable definition (setq usr3 (* (getvar "userr3"))) (if (= usr3 3600.0) (setq r3 50)) (if (= usr3 2400.0) (setq r3 25)) (if (= usr3 1200.0) (setq r3 12.5)) (IF (= USR3 600.0) (setq r3 6.25)) (if (= usr3 480.0) (setq r3 5)) (if (= usr3 360.0) (setq r3 3.75)) (if (= usr3 240.0) (setq r3 2.5)) (if (= usr3 120.0) (setq r3 1.25)) (IF (= USR3 384.0) (SETQ r3 4)) (IF (= USR3 192.0) (SETQ r3 2)) (IF (= USR3 128.0) (SETQ r3 1.33333333333)) (IF (= USR3 96.0) (SETQ r3 1)) (IF (= USR3 64.0) (SETQ r3 0.666666666667)) (IF (= USR3 48.0) (SETQ r3 0.5)) (IF (= USR3 32.0) (SETQ r3 0.333333333333)) (IF (= USR3 24.0) (SETQ r3 0.25)) (IF (= USR3 16.0) (SETQ r3 0.166666666667)) (IF (= USR3 12.0) (SETQ r3 0.125)) (IF (= USR3 8.0) (SETQ r3 0.083333333333)) (IF (= USR3 4.0) (SETQ r3 0.041666666667)) (IF (= USR3 2.0) (SETQ r3 0.020833333333)) (IF (= USR3 1.0) (SETQ r3 0.010416666667)) (IF (= USR3 0) (SETQ r3 1)) (setq newlayer "T-Data-Devc-Wall-N") (setq newlayercolor "3") (setq newlayerlineweight "0.50") (setq newlayerlinetype "Continuous") (setq newlayerplotstyle "Black") (setq lookupnew (tblsearch "LAYER" newlayer)) (setq atriblocknw "05-02-03-NW.dwg") ;end variable definition (command "ortho" "on") ;Sets Working Layer [color=Blue](initget "New Existing Demolition Future") (setq workinglayer (getKWord "\nEnter <N> New, <E> Existing, <D> Demolition, or <F> Future? [NEW]: ")) (cond ((or (not workinglayer) (eq workinglayer "New")) ;checks and/or defines layer to draw on (if (= lookupnew nil) (command "_-layer" "n" newlayer "s" newlayer "C" newlayercolor "" "L" newlayerlinetype "" "Lw" newlayerlineweight "" "PS" newlayerplotstyle "" "") (command "_-layer" "s" newlayer "") ); END IF ;Sets P1 TO start point of Receptacle and Inserts Block (setq p1 (getpoint "\nGet Insertion Point: ")) (command "_-insert" atriblocknw p1 r3 "") ) );end condition[/color] Quote
Lee Mac Posted September 24, 2009 Posted September 24, 2009 Quick tip - I would use a COND statment in place of all those IF's it'll make the program faster and is better programming practice. Quote
SteveK Posted September 24, 2009 Posted September 24, 2009 Quick tip - I would use a COND statment in place of all those IF's it'll make the program faster and is better programming practice. I agree. So instead of: (if (= usr3 3600.0) (setq r3 50)) (if (= usr3 2400.0) (setq r3 25)) etc... You would put: (Cond ((= usr3 3600.0) (setq r3 50)) ((= usr3 2400.0) (setq r3 25)) etc... [color=Blue](T (setq r3 1))[/color] ) The highlighted bit at the end is if there are no conditions met then it will set r3 (your scale) to 1. Which I think is your problem. If you need any further understanding of Condition statements have a look at http://www.cadtutor.net/forum/showpost.php?p=173196 Quote
Lee Mac Posted September 24, 2009 Posted September 24, 2009 You also have an "error" here - I say "error", it won't throw an error, but is unnecessary (setq usr3 (* (getvar "userr3"))) And why are you using USERR3 anyway? Quote
jubi23 Posted September 25, 2009 Author Posted September 25, 2009 Steve1! thank you! you're first post made me realize what was wrong my userr3 wasn't any of the any of the options throughout my if statements so i'm going to be changing it to just a formula that calculates usr3, then no more problems Thanks for the cond tip guys, i will keep that in mind in the future, but since i won't be using a million if statements anymore, good riddance! Lee Mac - you asked why i'm using userr3 We have a script where we can set the scale of our drawing, and we put the scale into the userr3 setting, then all our other scripts reference userr3 if they need the scale I didn't write all these original scripts, and i'm wondering, is there an easier way to find and set the scale of the drawing (like the value that goes into drawing setup page underscale) i tried dimscale, but that doesn't seem to affect the scale under drawing setup If i can just directly find/set the scale of the drawing i can aavoid the whole userr3 thing Quote
SteveK Posted September 27, 2009 Posted September 27, 2009 Glad that solved the main problem. Regarding getting/setting the scale, are you talking about the plot scale? I don't know if there's a system variable allocated to that. Maybe try asking that question in another section of the forum... Quote
SteveK Posted September 28, 2009 Posted September 28, 2009 Can I ask you Jubi where you would set the drawing scale manually? ie your userr3 value. Quote
Recommended Posts
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.