Lee Mac Posted January 5, 2010 Author Posted January 5, 2010 Examine these constructs: (setq ang (cond ((getangle "\nEnter Angle <0.0> : ")) (0.0))) (setq ang (getangle "\nEnter Angle <0.0> : ")) (if (not ang) (setq ang 0.0)) ;; ---------------------------------------- ;; (or *def* (setq *def* (/ pi 4.))) ;; *def* global (setq ang (cond ((getangle (strcat "\nEnter Angle <" (angtos *def* 0) "> : "))) (*def*))) (setq ang (getangle (strcat "\nEnter Angle <" (angtos *def* 0) "> : "))) (if (not ang) (setq ang *def*)) Quote
chulse Posted January 6, 2010 Posted January 6, 2010 Cool! This is going to save me hours. I have the rotation prompt working now. Thanks. Would it be possible to add a tracking/pause/break mechanism? Some way to allow the user to stop mid-way through a given csv, do other tasks and then resume where they left off? I could see that for large data sets, this may be a huge help. Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 Would it be possible to add a tracking/pause/break mechanism? Some way to allow the user to stop mid-way through a given csv, do other tasks and then resume where they left off? I could see that for large data sets, this may be a huge help. Hmmm... good question. The problem is that in LISP you don't really get much versatility with the read-line/write-line functions. My thoughts at the minute are to include a counter (global variable - or maybe blackboard referenced, if using multiple docs), incremented with each read-line, and then when the command is re-invoked, perform read-line the number stored in the counter and proceed as normal from there. But of course, there may be a better solution. Lee Quote
chulse Posted January 6, 2010 Posted January 6, 2010 Well, could you point me in a direction to try there? (what functions might I research?) Could a USER variable possibly be used to hold the position in the csv document? Then the next thing would be to add a "Begin at the beginning?" prompt ... or maybe ... could we add a means to select the start point in the list at the beginning of the program? Quote
chulse Posted January 6, 2010 Posted January 6, 2010 One other question - I'd like to force the block to be inserted on a specific layer every time. I assume I should check to see if the layer first exists, then create it if it doesn't? Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 With the counter - lets say it is a global variable (you can do what you like to store it). You already have all the functions you need, just read-line, (and maybe repeat/while). Then, when you reach the end of the file, set the counter back to zero. You could add a prompt to choose to start at the beginning, perhaps using getkword, and set the counter accordingly. As for layer, either set CLAYER before inserting the block, or use vla-put-layer on the resultant block object. Use tblsearch to check if the layer exists, and then either a command call, vla-add, or entmake to create the layer. Lee Quote
chulse Posted January 6, 2010 Posted January 6, 2010 So the placement in the list (x) should be stored as a global var and called back at the beginning af each iteration? Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 So the placement in the list (x) should be stored as a global var and called back at the beginning af each iteration? Just use a counter to count the number of times that read-line is invoked. So, at the top of the code: (or *counter* (setq *counter* 0)) Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 Example to show proof of concept: (defun c:test (/ file ofile nl) (or *counter* (setq *counter* 0)) (if (setq file (getfiled "File" "" "txt" ) (progn (if (not (zerop *counter*)) (progn (initget "Start Continue") (setq *counter* (if (= "Start" (getkword "\n[s]tart of File or [C]ontinue? <Continue> : ")) 0 *counter*)))) (setq ofile (open file "r")) (repeat *counter* (read-line ofile)) (while (progn (setq nl (read-line ofile)) (cond ( (not nl) (setq *counter* 0) nil) ( (setq *counter* (1+ *counter*)) (print nl) (initget "Yes No") (if (/= "No" (getkword "\nContinue? <Yes> : ")) t))))) (close ofile))) (princ)) Quote
chulse Posted January 6, 2010 Posted January 6, 2010 But how do I pass that back to set the position in the list? ...ok, you beat me to it... Quote
chulse Posted January 6, 2010 Posted January 6, 2010 Can you help me understand the differences/uses/syntax for local vs global variables? Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 The only difference between local and global variables is that global variables hold their values after program completion, and locals don't. Local variables are declared in the brackets that appear after the "defun c: xx" part. It is better to use obscure symbols for global variables to prevent clashes with variables from other programs, but, you could use whatever you like. Quote
chulse Posted January 6, 2010 Posted January 6, 2010 Does the "/" in the defun part mean anything? Does the use of asterisks (*var*) mean anything, or is that just your way to keep global vars unique? And do global vars remain within the DWG after it's closed? Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 Does the "/" in the defun part mean anything? Yes, read the help file on defun, arguments before, variables after. Does the use of asterisks (*var*) mean anything, or is that just your way to keep global vars unique? Unlike C/C++ etc asterisks don't mean pointers - I just use them to make the variable less common. And do global vars remain within the DWG after it's closed? No, all unreleased objects/variables in the ActiveDocument namespace are released/set to nil when the drawing is closed. You can store variables using the AutoCAD blackboard namespace so that they may be referenced between documents in one ACAD session, but these too will be set to nil during the garbage collection when ACAD is closed. Quote
chulse Posted January 6, 2010 Posted January 6, 2010 Unlike C/C++ etc asterisks don't mean pointers - I just use them to make the variable less common. seems like a good practice. As for the Vars - could one use the USERI vars to store a value in the dwg (that is preserved on close/open)? Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 As for the Vars - could one use the USERI vars to store a value in the dwg (that is preserved on close/open)? I never really use the USERI vars... but give it a go, let me know what you find Quote
chulse Posted January 6, 2010 Posted January 6, 2010 I can't seem to find examples of syntax for the vla-add and vla-put-layer functions - could you post some please? Quote
chulse Posted January 6, 2010 Posted January 6, 2010 I never really use the USERI vars... but give it a go, let me know what you find I looked back at the VBA tool I have and I remembered correctly that I used those vars there with success... so I assume I can do the same here in lisp... TextBoxScale.Text = ThisDrawing.GetVariable("UserI1") + 1 ThisDrawing.SetVariable "UserI1", Val(TextBoxScale.Text) ROTATION.Value = ThisDrawing.GetVariable("UserR1") ThisDrawing.SetVariable "UserR1", Val(ROTATION.Value) Quote
Lee Mac Posted January 6, 2010 Author Posted January 6, 2010 I can't seem to find examples of syntax for the vla-add and vla-put-layer functions - could you post some please? If you look up those functions in the VLIDE help, it will give the necessary arguments, but then if you are new to VL you may need more clarification, so here: To set an object's layer (assuming it exists): (vla-put-layer <obj> "Layer Name") To Add a layer to the Layer Collection: (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) "Layer Name") But you shouldn't reference vlax-get-acad-object multiple times, so this is better: (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-add (vla-get-layers doc) "Layer Name") In this way, you can use "doc" in other functions. Quote
chulse Posted January 11, 2010 Posted January 11, 2010 Just in case anyone was watching... And thanks again to LeeMac!! - this has been a massive workflow improvement for us and also a great learning experience for me. TCOT-TREE.lsp 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.