Glen_Johnston
2007-07-01, 02:07 AM
Hi,
I design truck bodies with compartments of various sizes. The compartment is drawn using a rectangle. I have written a lisp program that extracts the width and height data from the rectangle, and then it extracts the compartment location, number, and hinge type from a text object located within the rectangle. After that has been done, the program generates a cut list for the aluminum extrusions that make up both the door jamb and door frame. The program works great, but I would like to improve one aspect of it.
The program fails if the person using it (mostly me) picks empty space for either the rectangle or text, or miss-picks the wrong type of object for either the rectangle or text. I would like to add a “loop-back” (Please try again!...) until the correct object has been picked at the proper time.
I did a search and did find some threads that showed a few different methods to do this, but I just could not figure out how to include that code into the selection portion of my program (shown below)
One method found used “errno” 7 if there was a pick in empty space, and another method tested the selection to see if it was the correct type of object and used a “while” loop. As I said, I just cannot figure out how to do it. Any help would be appreciated. If the entire program is needed, let me know.
Thanks, Glen
This program will be used on AutoCAD 2005, 2006, & 2007
; Get raw compartment dimensions
(setq rect (entget (car(entsel "SELECT COMPARTMENT"))))
(print)
(setq corner1 (nth 14 rect))
(setq corner2 (nth 22 rect))
(setq high (- (caddr corner1) (caddr corner2)))
(setq wide (- (cadr corner1) (cadr corner2)))
(setq rawheight (abs high))
(setq rawwidth (abs wide))
(setq entSelection (entsel "SELECT COMPARTMENT NUMBER: ")) ;select Compartment NAME/NUMBER/HINGE STYLE - Example: CS-1-S
(print)
(setq entstring (cdr (assoc 1 (entget (car entSelection))))) ;extract text value
(setq answer (substr entstring 6)) ;extract hinge style from text value
(setq entstring (substr entstring 1 4)) ;reduce text value to 4 places
I design truck bodies with compartments of various sizes. The compartment is drawn using a rectangle. I have written a lisp program that extracts the width and height data from the rectangle, and then it extracts the compartment location, number, and hinge type from a text object located within the rectangle. After that has been done, the program generates a cut list for the aluminum extrusions that make up both the door jamb and door frame. The program works great, but I would like to improve one aspect of it.
The program fails if the person using it (mostly me) picks empty space for either the rectangle or text, or miss-picks the wrong type of object for either the rectangle or text. I would like to add a “loop-back” (Please try again!...) until the correct object has been picked at the proper time.
I did a search and did find some threads that showed a few different methods to do this, but I just could not figure out how to include that code into the selection portion of my program (shown below)
One method found used “errno” 7 if there was a pick in empty space, and another method tested the selection to see if it was the correct type of object and used a “while” loop. As I said, I just cannot figure out how to do it. Any help would be appreciated. If the entire program is needed, let me know.
Thanks, Glen
This program will be used on AutoCAD 2005, 2006, & 2007
; Get raw compartment dimensions
(setq rect (entget (car(entsel "SELECT COMPARTMENT"))))
(print)
(setq corner1 (nth 14 rect))
(setq corner2 (nth 22 rect))
(setq high (- (caddr corner1) (caddr corner2)))
(setq wide (- (cadr corner1) (cadr corner2)))
(setq rawheight (abs high))
(setq rawwidth (abs wide))
(setq entSelection (entsel "SELECT COMPARTMENT NUMBER: ")) ;select Compartment NAME/NUMBER/HINGE STYLE - Example: CS-1-S
(print)
(setq entstring (cdr (assoc 1 (entget (car entSelection))))) ;extract text value
(setq answer (substr entstring 6)) ;extract hinge style from text value
(setq entstring (substr entstring 1 4)) ;reduce text value to 4 places