Author Topic: Help with a LSP routine  (Read 310 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Mosquito
  • Posts: 8
Help with a LSP routine
« on: January 28, 2021, 02:02:38 PM »
I am trying to do a very simple thing and i cant figure it out....

I am trying to have a LISP that will do the following:

1. Draw Line
2. Insert a Block at the start point of that line
----this should happen automatically

draw line...exit command...block gets inserted at the start point

seems simple but i dont know what I am doing...

Code: [Select]
(defun varget ()
(setq lis '("orthomode")) ;define system variables
(setq var (mapcar 'getvar lis))
(setq var1 '(1)) ;set system variables
(setq no 0)
(repeat (length lis)
(setvar (nth no lis) (nth no var1))
(setq no (1+ no))
)
(princ)
)

(defun varset () ;reset system variables above to 0
(setq no 0)
(repeat (length lis)
(setvar (nth no lis) (nth no var))
(setq no (1+ no))
)
(princ)
)

(princ)

(defun C:wire ()
(progn
(varget)
(setq prevlayer (getvar "clayer"))
(setq P (getstring "Audio(A)/Video(V)/Comm(CO)/Coax(R)/Control(C)/(N)etwork/(P)ower:"))
(command "SNAP" "1")
(IF (= P "V")(command "-LAYER" "M" "VIDEO" "C" "150" "" "" "PLINE" PAUSE))
(IF (= P "A")(command "-LAYER" "M" "AUDIO" "C" "94" "" "" "PLINE" PAUSE))
(IF (= P "CO")(command "-LAYER" "M" "COMM" "C" "206" "" "" "PLINE" PAUSE))
(IF (= P "R")(command "-LAYER" "M" "COAX" "C" "44" "" "" "PLINE" PAUSE))
(IF (= P "C")(command "-LAYER" "M" "CONTROL" "C" "10" "" "" "PLINE" PAUSE))
(IF (= P "N")(command "-LAYER" "M" "NETWORK" "C" "210" "" "" "PLINE" PAUSE))
(IF (= P "P")(command "-LAYER" "M" "POWER" "C" "7" "" "" "PLINE" PAUSE))
(while (> (getvar "CMDACTIVE") 0) (command "\\"))
(setvar "clayer" prevlayer)
(varset)
(princ)
);Progn
  );defun

the code above allows me to select a type and then draw that line on a certain layer

I would like this same thing but at the end insert the block....I currently do this in 2 steps...just trying to make it easier...i currently call this lisp up via a toolbar button that is coded with what type of line to make...multiple buttons.

Thanks in advance!


BIGAL

  • Swamp Rat
  • Posts: 665
  • 30 + years of using Autocad
Re: Help with a LSP routine
« Reply #1 on: January 28, 2021, 06:51:25 PM »
Don't see a problem when you draw a line (command "line" pt1 pt2 "") then pt1 is start point,
so get angle (angle pt2 pt1),
do a offset from start point (setq pt3 (polar pt1 ang off)),
then just (command "-insert" blkname pt3 ......
A man who never made a mistake never made anything

AVCAD

  • Mosquito
  • Posts: 8
Re: Help with a LSP routine
« Reply #2 on: February 01, 2021, 02:04:00 PM »
HI BIGAL,

Thanks for the Help. I was able to make this work with your suggestions. Works like a charm now.

Thanks again!