Author Topic: Newbie to world of (Lost in Stupid Parentheses) errr..(List)  (Read 100352 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #300 on: November 20, 2003, 02:17:47 PM »
Andre, did you test the routine? If so, then you might notice that the pline it allows you to draw is not put on the layer and drawn with the linetype that you want. Why?

Look at the last 4-5 lines. It calls the PLINE command alright, but it is not allowed to finish before setting 3 system variables. In other words: it resets the environment before drawing any plines.

If you can solve this problem then you have written yourself a nice little routine.

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #301 on: November 20, 2003, 02:46:01 PM »
I know how difficult that can be, so here's an old set of functions that should help. They should be simple enough.
Code: [Select]
(defun setpick ()
     (if (= (getvar "ltscale") 1)
 (setvar "ltscale" 48)
     )
     (command ".layer" "m" "an_notes" "c" "4" "" "")
     (setq lt (getvar "ltscale"))
     (setvar "OSMODE" 512)
     (setq a (getpoint "\nStart point of arrow: "))
     (setvar "OSMODE" 0)
     (setq b (getpoint a "\nDirection of arrow: "))
)

(defun ldrawing ()
     (setq waro (* laro 0.6))
     (setq aaro (angle a b))
     (command
 "PLINE"
 a
 "w"
 "0"
 waro
 (polar a aaro laro)
 "w"
 "0"
 "0"
 b
     ) ;_ COMMAND
     (setq c b)
     (while (setq c (getpoint c "\nNext point: "))
 (command c)
     ) ;_ WHILE
     (command "")
)
The part of the code in reference to Stig's suggestion is the end of the last function starting with (setq c b)

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #302 on: November 21, 2003, 04:10:03 AM »
Just wanted to add another, more generally purposed variant of this technique:

Code: [Select]
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #303 on: November 21, 2003, 07:50:06 AM »
Quote from: SMadsen
Andre, did you test the routine? If so, then you might notice that the pline it allows you to draw is not put on the layer and drawn with the linetype that you want. Why?

Look at the last 4-5 lines. It calls the PLINE command alright, but it is not allowed to finish before setting 3 system variables. In other words: it resets the environment before drawing any plines.

If you can solve this problem then you have written yourself a nice little routine.


I've tested the routine and it's crashing at some points but i know what is doing that but i want to take care of that after i get this first issue out of the way.

I've looked at the last 4-5 lines like you said and can't see what you're tellin me.. I don't know what you're tryin to say.

Quote

Just wanted to add another, more generally purposed variant of this technique:


code:
--------------------------------------------------------------------------------
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)
--------------------------------------------------------------------------------




Can you explain what you just wrote here... i have no clue
 :?

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #304 on: November 21, 2003, 08:44:16 AM »
Quote from: amgirard2003
Can you explain what you just wrote here... i have no clue :?

Not without having you do some tests. It's way easier to illustrate if you run the functions below and read the accompanying comments.

First start a fresh drawing. Create a new layer called "612" and set it to color red. Set layer "0" currently active and leave its color as the default 7 (white or black). Now load this test routine and run it. Draw one or two lines with it.

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE")
  (setvar "CLAYER" "0")
)


This little routine sets the layer "612" active, issues a LINE command and resets the layer to "0". The intension is naturally to put all new lines on layer "612" .. but it doesn't. Your lines will be put on layer "0".

Whenever AutoLISP issues an AutoCAD command with the COMMAND function, it does not stop up and wait for AutoCAD to do its stuff. This means that before you even get to click at the start point, AutoLISP will have speeded ahead and already executed any subsequent code. Thus, AutoLISP sets the layer to "0" before AutoCAD gets a chance to ask you to draw a line.

So, how do you politely ask AutoLISP to stop and wait while the user finishes a command? You already know one way: to use the symbol PAUSE.
But PAUSE will only hold AutoLISP back while specifying a single parameter in a command. Try this slightly modified version of the routine above:

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE" pause pause)
  (setvar "CLAYER" "0")
)


Cool. Now we at least get to draw a single line on the layer that we wanted. But if we stay in the command and want to draw more lines, AutoLISP will jump the speeder after the last PAUSE symbol and set the layer to "0".

We could put more PAUSE's in there but who are we to tell the user how many lines s/he is allowed to draw? So we'll have to find a way to stop AutoLISP entirely while there is a command active in AutoCAD.
This is what the system variable CMDACTIVE is for. It's simply a flag that tells if a command is active. If there are no commands currently running, this system variable will be 0 and all we have to do is check for that instance. By running a loop while a command is active we can detect when AutoCAD has finished doing its stuff. While a command is active, we simply issue the PAUSE symbol that allows the user to communicate with the command:

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (setvar "CLAYER" "0")
)


Voíla, no more speeding tickets for AutoLISP. It sits neatly in its loop and supplies PAUSE's to the command until the user has finished. Then it sets the layer to "0".

Anonymous

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #305 on: November 21, 2003, 11:02:43 AM »
Could someone go over the proper way to "SET" and "GET" system variables?
I'm doing something wrong cause the routine keep crashing on me and and and error of (System variables rejected "ltscale" "0")
I don't know what i'm doin wrong that is making my routine crap out

Code: [Select]
(defun c:nl (/ ans clay cltype pwidth)
  (prompt "Run with Phil's routine only")
; tell the user to use it with Phil's routine
  (initget 0 "Three Double Single seCondary E F") ; Capital letters of all the Linetypes
  (setq ans
(getkword
  "\nSelect Line [Three/Double/Single/seCondary/E(600)/F(208)]: <> "
)
  )

  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq clay (getvar "clayer"))
  (setvar "clayer" "0")
  (setq ltype (getvar "celtype"))
  (setvar "celtype" "bylayer")
  (setq scal (getvar "ltscale"))
  (setvar "ltscale" 0)
  (setq pwidth (getvar "plinewid"))
  (setvar "plinewid" 0)


I wanna keep it simple for right now, so please try and keep that in mind
Thanks

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #306 on: November 21, 2003, 11:09:29 AM »
There is no way to make system variables rattle on the settings that they accept. Before changing a system variable programmatically, it is expected of the programmer to know the allowed settings beforehand. If in doubt, always look up the system variable in the help reference before attempting to SETVAR it.

It makes no sense to set LTSCALE to 0. From the help file:

Quote
Type: Real
Saved in: Drawing
Initial value: 1.0000

Sets the global linetype scale factor. The linetype scale factor cannot equal zero.

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #307 on: November 21, 2003, 11:09:44 AM »
ltscale can't receive the value of zero. Anything else will work.

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #308 on: November 21, 2003, 11:10:56 AM »
Beaten by a mere second.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #309 on: November 21, 2003, 11:19:16 AM »
Thanks Guys,
I just found that out... I was checking the variables and found what i had to set it too for it to work..

Well it seems to be working great but there are some good old bugs i'm gonna have to get rid of.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #310 on: November 24, 2003, 09:30:22 AM »
Hey Guys,

O.k. here's the bugs i have to work out so be on the lookout for questions to come.

1) If the layer does not exist, then create it.

First question and i know we've been through this but wanna refresh,
Do i use the tblsearch function for this?

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #311 on: November 24, 2003, 09:34:37 AM »
That's one way.

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #312 on: November 24, 2003, 09:36:49 AM »
Think of TBLSEARCH and TBLNEXT as look-up functions. You can query the so-called symbol tables with them in order to get some common info on an entry, but you can't modify existing entries nor create new entries.

If a layer doesn't exist, I'd recommend that you use the LAYER command to create it - for now at least.

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #313 on: November 24, 2003, 09:39:21 AM »
Oh, just saw Daron's reply and have to rethink. Yes, TBLSEARCH is an excellent approach to test if a layer exists.

For example, to create a layer if it doesn't exist:

(if (not (tblsearch "LAYER" "612"))
  (command "LAYER" "Make" "612" "")
)

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #314 on: November 24, 2003, 09:40:25 AM »
Even if a layer does exist, using command layer to create it will not be a problem. All it will do is set the layer current and if you told it to be red instead of whatever color it already was, it would become red. So, you wouldn't need an if function either.