Author Topic: INITIALIZE NONE EXISTANT VAR  (Read 3492 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: INITIALIZE NONE EXISTANT VAR
« Reply #15 on: June 21, 2012, 01:55:00 PM »
Not sure what you mean.  If i open a dwg, and !cmdrun it come back nil, which i was trying to trap.

Are you actually running the function (DrawCable) before testing the variable?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: INITIALIZE NONE EXISTANT VAR
« Reply #16 on: June 21, 2012, 02:01:18 PM »
Lee, i think yes.  When I first opened the dwg, the first command I called was (DrawCable)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Gasty

  • Newt
  • Posts: 90
Re: INITIALIZE NONE EXISTANT VAR
« Reply #17 on: June 22, 2012, 09:57:25 PM »
Hi,

May be CMDRUN is set to a non numeric value like a string or a list, so it pass the test.

Gaston Nunez

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: INITIALIZE NONE EXISTANT VAR
« Reply #18 on: June 23, 2012, 02:24:58 AM »
Hi,

May be CMDRUN is set to a non numeric value like a string or a list, so it pass the test.

Gaston Nunez
The biggest reason for localizing variables! Since now you have to go through every bit of code you ever had to try and find the culprit.

As a side note, to try and avoid this, when making such a global variable the convention is to prefix and suffix it with asterisks (to make it clear that it's meant as a global var). I.e. the var's name should be *CMDRUN* ... makes it easier to find in other codes as well, so your search becomes less daunting.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

DEVITG

  • Bull Frog
  • Posts: 481
Re: INITIALIZE NONE EXISTANT VAR
« Reply #19 on: June 23, 2012, 11:42:09 PM »
To  CmdrDuh

What value is set to osmode here ?

Code: [Select]
(setvar "orthomode" 0)
  (setvar "osmode"
  (setq   pt1 (getpoint "\nPick Cable Start: ")

If your task is only to draw 6 cable , why not to use a repeat.


Code: [Select]
(defun DrawCable (/

 ANG CLAY MPT OSM OTH PT1 PT2 PT3

                  )
  (setq clay (getvar "clayer"))
  (setq osm (getvar "osmode"))
  (setq oth (getvar "orthomode"))
  (setvar "orthomode" 0)
 
  (repeat 6
    (setvar "osmode"  512);_ I set it to near to
  (setq   pt1 (getpoint "\nPick Cable Start: ")
   pt2 (getpoint pt1 "\nPick Cable Endpoint: ")
   ANG (ANGLE pt1 pt2)
  )
  (setvar "osmode" 0)
  (SETQ mpt (POLAR pt1 (ANGLE pt1 pt2) (/ (DISTANCE pt1 pt2) 2)))
  (cond
    ((AND (<=  ANG (/ pi 2 )) (>  ANG 0))  (setq pt3 (polar mpt (+ ang  ( / pi 2)) (/ (DISTANCE pt1 pt2) 5))))
    ((AND (<=  ANG pi ) (>  ANG ( / pi 2)))  (setq pt3 (polar mpt (- ang  ( / pi 2)) (/ (DISTANCE pt1 pt2) 5))))
    ((AND (<=  ANG ( * pi 1.5)) (>  ANg pi ))(setq pt3 (polar mpt (+ ang   ( / pi 2)) (/ (DISTANCE pt1 pt2) 5))))
    ((AND (<=  ANG ( * pi 2) ) (>  ANG ( * pi 1.5) ))(setq pt3 (polar mpt (- ang   ( / pi 2)) (/ (DISTANCE pt1 pt2) 5))))
    ((=  ANG 0)(setq pt3 (polar mpt (- ang   ( / pi 2)) (/ (DISTANCE pt1 pt2) 5))))
  )
  (command "-layer" "m" "SITE-BUSS" "C" 1 "SITE-BUSS" "")
  (command "pline" pt1 "w" 2 2 "a" "s" pt3 pt2 "")
    );_ end repeat
 
  (setvar "orthomode" oth)
  (setvar "osmode" osm)
  (setvar "clayer" clay)
)
« Last Edit: June 24, 2012, 12:41:15 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10