Help with a LISP function for hatching

Help with a LISP function for hatching

murmanator
Advocate Advocate
946 Views
4 Replies
Message 1 of 5

Help with a LISP function for hatching

murmanator
Advocate
Advocate

Hello, Im not really a programmer but can fumble my way through. Hoping I can get some help with this function I have for hatching. In the code below, I am calling a separate function which isolates the layers necessary to perform the hatch, then it prompts the user to specify the internal point. Once you click in the area it inserts the hatch and returns a prompt with the square footage. Finally it returns the layer state to what it was previous to calling the function.

 

I have 2 issues here: First I can only click in one area. I need to be able to click in multiple areas and have it insert the hatch into all of them, then perform the rest of the function. Second, if there is already a hatch of the type being called by the function in the drawing, calling this function again does insert the hatch into the area but then it stops. In this case, I could live with not getting the square footage prompt but I would really like the layer state to be returned to the previous state. This is not happening. If issue 1 was resolved it would probably make issue 2 moot.

 

Thanks for looking and for any help

 

(defun C:HATCH-TRAV () (HTR))
(defun HTR (/ SQFT)
(GV)
(0V)
(ppa-L-DECKISO)
(if (= (assoc 0 (tblsearch "layer" "HATCH-DECK")) nil)
(vl-cmdf "-Layer" "M" "HATCH-DECK" "L" "CONTINUOUS" "" "C" "9" "LW" ".05" "" "")
(vl-cmdf "-Layer" "S" "HATCH-DECK" "")
)
(vl-cmdf "-HATCH" "P" "URBANA_STONE_B2" "1" "0" "")
(vl-cmdf "-HATCH" PAUSE "")
(setq SQFT (GET-HATCH-AREA "URBANA_STONE_B2" "HATCH-DECK"))
(alert (strcat "TRAVERTINE : " SQFT " sqft"))
(dict-put "GRANITE" "SQFT" (ATOI SQFT))
(VL-CMDF "_HATCHTOBACK")
(SV)
(princ)
)

0 Likes
Accepted solutions (1)
947 Views
4 Replies
Replies (4)
Message 2 of 5

scot-65
Advisor
Advisor
Without supplying complete code, I will emphasize program structure.
First of all, layer "Make" method will set the newly created layer as current.

Create a list of points (with [Enter] as the user's escape) and collect
these list of points into a LIST.

(while (setq pt (getpoint "Specify internal point: "))
(setq pts (list (cons pt pts))) ;<-this may be incorrect
);while

If the list is successful, execute the main program:
Use FOREACH to iterate thru the list.
(foreach x pts
...
<<replace PAUSE with x>>
...
);foreach

<untested>
???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 3 of 5

murmanator
Advocate
Advocate

Thank you for the reply, Scot. Ive been trying to implement what you suggested unfortunately Im not skilled or knowledgeable enough to get anything working. Im not really sure what you mean by "program structure" either. I suppose it has something to do with the order of the steps? This code was written by a programmer no longer with the company and Im trying to revise it to do what I want.

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

Not sure about your second issue, but if you're right that fixing issue 1 will make it moot, try something like:

 

(defun C:HATCH-TRAV ()
  (HTR)
); defun
(defun HTR (/ SQFT)
  (GV)
  (0V)
  (ppa-L-DECKISO)
;;;  (if (= (assoc 0 (tblsearch "layer" "HATCH-DECK")) nil)
;;;  much simpler to do just:
  (if (not (tblsearch "layer" "HATCH-DECK"))
;;;    (vl-cmdf "-Layer" "M" "HATCH-DECK" "L" "CONTINUOUS" "" "C" "9" "LW" ".05" "" "")
;;;  Continuous is default linetype [no need to specify it]; missing layer assignment for color:
    (vl-cmdf "-Layer" "M" "HATCH-DECK" "C" "9" "" "LW" ".05" "" ""); then
    (vl-cmdf "-Layer" "S" "HATCH-DECK" ""); else
  ); if
  (vl-cmdf "-HATCH" "P" "URBANA_STONE_B2" "1" "0" "")
;;;  (vl-cmdf "-HATCH" PAUSE "")
;;;  to allow more than one area to be picked, try having Bhatch wait for input until done:
  (command "_.bhatch")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (setq SQFT (GET-HATCH-AREA "URBANA_STONE_B2" "HATCH-DECK"))
  (alert (strcat "TRAVERTINE : " SQFT " sqft"))
  (dict-put "GRANITE" "SQFT" (ATOI SQFT))
  (VL-CMDF "_HATCHTOBACK")
  (SV)
  (princ)
); defun

I do find it a little odd to define a command [the first longer name] that only calls another function that is then defined -- the functionality could just be built right into the command definition, without "middle-man" of the embedded (HTR) function at all.

 

Kent Cooper, AIA
0 Likes
Message 5 of 5

murmanator
Advocate
Advocate

THats it! Thank you Kent. Perfect.

Yeah Im not sure why the first command and embedded command are setup like that. Our previous programmer did that on almost all his commands so I just thought that was a thing and went with it. In any case, problem solved and thank you so much!

0 Likes