View Full Version : object properties into attributes
rstiles
2009-07-15, 04:40 PM
I'm trying to write a lisp that populates several attributes the attribute I am having troubles with is selecting a polyline to get the layer name to insert into the attribute.
End result of this lisp is to place a block under a polyline that has a piece of txt. Populate that block’s attributes with the txt content and the plines layer and user define the other attributes
Any suggestions would be useful.
rstiles
2009-07-15, 05:18 PM
I figured out how to get the info of the last drawn object but I need the currently selected object
(entget (entlast))
(cdr (assoc 8 el))
But what do I use instead of "entlast"
And does anyone know of a list of "commands and definitions" either on the internet or a book I can buy?
T.Willey
2009-07-15, 05:40 PM
The help files have a listing of all the functions that are built into Lisp through Autocad. If you want to select an entity, then look at ' entsel '.
msretenovic
2009-07-15, 05:43 PM
I figured out how to get the info of the last drawn object but I need the currently selected object
(entget (entlast))
(cdr (assoc 8 el))
But what do I use instead of "entlast"
And does anyone know of a list of "commands and definitions" either on the internet or a book I can buy?
Look into the SSGET function - for an implied selection (objects selected BEFORE your routine runs), take a look at the "I" option for SSGET.
i.e.
;;get currently selected objects
(setq ss (ssget "I"))
;;if no selection...
(if (null ss)
(progn
;;...get user selected objects
(princ "\nSelect an object(s): ")
(setq ss (ssget))
)
)
rstiles
2009-07-15, 05:49 PM
I used entsel but I can’t figure out how to add it into the entget. Each way I have tried I get bad argument
(setq fixt (entget (entsel “Select Fixture”)))
I also tried
(setq fixt (entsel “Select Fixture”))
(entget fixt)
Am I using it right?
msretenovic
2009-07-15, 05:56 PM
I used entsel but I can’t figure out how to add it into the entget. Each way I have tried I get bad argument
(setq fixt (entget (entsel “Select Fixture”)))
I also tried
(setq fixt (entsel “Select Fixture”))
(entget fixt)
Am I using it right?
When using ENTSEL, you will need to use ENTGET (as you have tried) to get the object. However, you will need to examine what ENTSEL returns - a list containing an entity and the point that was chosen (i.e. (<Entity name: 5296482> (5.1289 6.4293 0.0)) ). To get the entity from ENTSEL, you will need to use CAR before passing the result to ENTGET. Your line of code would read as such:
(setq fixt (entget (car (entsel "Select Fixture"))))
rklee
2009-07-15, 05:58 PM
To get the information using entget try
(setq fixt (entget (car (entsel "Select Fixture"))))
rstiles
2009-07-15, 07:03 PM
Awesome I might have some more questions but that answered it for now
rstiles
2009-07-15, 09:09 PM
Ok got every line to work but when I piece it together and run the lisp it skips the user defined stuff. is there a break I need to put in?
rstiles
2009-07-15, 09:32 PM
Scratch that. I for got to run it as a lisp I was dropping it on the command line. But when I run it as a lisp it gives me a syntax error on load. It tells me it loaded ok. I don’t even run the command
rstiles
2009-07-15, 09:43 PM
sorry here is the code im trying to test. what am i doing wrong?
(defun test (/ Name Fixt P1)
(setq Name (entget (car (entsel "Select Fixture Type")))
Fixt (entget (car (entsel "Select Light Fixture")))
P1 (getpoint "Select insertion point")
)
(Command "attdia" "0")
(Command "insert" "iom" p1 "1" "1" "0" "" "" "" "" "" "" "" "" "" "" "" "")
(command "attdia" "1")
)
rstiles
2009-07-16, 01:41 PM
nobody knows what i am doing wrong?
T.Willey
2009-07-17, 01:16 AM
If you not going to fill in the attributes at insert, then look into the system variable ' attreq '.
As for the code, it doesn't look wrong, but you don't say what the error from the command line is, or I missed it.
You are asking for the user to pick two items... why? You don't do anything with them yet. So the only thing the code needs is the picked point, because that is all you are using in the insert command, and that is the only command.
You can also pass the command reals instead of strings. So:
(command "_.insert" "iom" pl 1. 1. 0.)
RobertB
2009-07-17, 01:29 AM
You are not using the selected objects in the test routine, so I've dropped them from this sample code. Please note that when changing system variables it is important for you to provide error handling to restore the original environment. And if you do that in an error situation, you might as well do it for a clean exit as shown.
(setvar 'CmdEcho 0) ; turn off command echo globally
(defun C:Test (/ *error*) ; localize the error handler
;; error handler
(defun *Error* (msg) ; the function requires a single argument
(cond ((null msg)) ; if no message provided, don't show one
((princ msg))) ; error happened, show error
(setvar 'AttReq oldAttReq) ; restore old setting
(setvar 'AttDia oldAttDia) ; restore old setting
(princ)) ; clean exit
;; main code
(setq oldAttReq (getvar 'AttReq)) ; store old setting
(setvar 'AttReq 1) ; make new setting
(setq oldAttDia (getvar 'AttDia)) ; store old setting
(setvar 'AttDia 0) ; make new setting
(princ "\nSpecify insertion point: ") ; prompt user since command echo is off
(command "._-Insert" "IOM" "_s" 1 "_r" 0 pause) ; provide scale/rotate options before pt
;; note that the below is really bogus since AttReq=0 would skip attributes
(while (> (getvar 'CmdActive) 0) (command "")) ; loop until all attributes are skipped
;; the below would be the alternate that allows you add the needed data
;;; (command "first attribute data")
;; repeat the above as many time as needed to deal with all the attributes
(*error* nil)) ; no error, clean exit
rstiles
2009-07-17, 10:05 PM
thanks i will keep that in mind but i really don't understand error handling yet. im a super novice at this right now.
and the worst is the scope of what i was trying to achieve has changed so i need to take a different route.
now instead of selecting and item one at a time i need to select multible objects (which are rectangles) with a window and place a block at each lower left corner. i have scraped trying to pick up the text string contents and just focusing on setting the layer the same as the pline then placing the block and filling an attribute out with the layer name
but i have never used selection sets. so im a bit confused how to sort them after i have selected one
and i have messed around with the info of the rects and they are all drawn from a different start point. so with entsel i don't have a consistent insertion point to use. is there a way i can select a corner based on the extents of an object?
im starting to think this is out of my abilities.
ReachAndre
2009-10-07, 08:29 PM
I'm trying to write a lisp that populates several attributes the attribute I am having troubles with is selecting a polyline to get the layer name to insert into the attribute.
End result of this lisp is to place a block under a polyline that has a piece of txt. Populate that block’s attributes with the txt content and the plines layer and user define the other attributes
Any suggestions would be useful.
Here's a way to do it with fields so that it can stay current. I too am bad at error checking.
I put this together pretty rough so it can probably use a good smoothing over.
(defun c:attadd (/ bname cdimscale oatt1 oid oidlay)
(setq cdimscale (getvar "dimscale"))
(setq bname "Test Block")
(if (not att1)(setq att1 "XXX"))
(setq oatt1 att1)
(if (=
(setq att1 (getstring T (strcat "Specify Att1 <" oatt1 ">: ")))
"")
(setq att1 oatt1)
)
(setq oid (vla-get-ObjectId (vlax-ename->vla-object (car (entsel "\n Select Source Object: ")))))
(setq oidlay (strcat "%<\\AcObjProp Object(%<\\_ObjId "(rtos oid 2 0) ">%).Layer>%"))
(command "-insert" bname "s" cdimscale "r" 0 pause)
(command oatt1 oidlay)
(princ))
Andre
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.