TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: T.Willey on July 06, 2007, 02:27:56 PM
-
I could have use this when I was trying to use entmake and couldn't figure out what codes needed to be there. I just thought of this today, and have one way, non-recursive, and thought it might be a fun little challenge. I don't think mine works quite right as is, as I think there are some codes that are shown, but don't need to be there.
Rules:
The functions will return the minimum codes to create an entity like the one supplied. What is supplied to the function can be either the entity, or the entities dxf code list. Mine takes the code list.
Edit: Change the title to clarify some confusion.
-
Here is what mine returns. Just as an example.
Command: (MinEntmake (entget (car (entsel))))
Select object: ((0 . "LINE") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (100 . "AcDbLine") (10 28.8276 7.62283 0.0) (11 22.5888 14.0073 0.0))
-
Hi, here's my contribution
(defun dxf_min (elst / new)
(while elst
(if (entmake (append new (cdr elst)))
(entdel (entlast))
(setq new (append new (list (car elst))))
)
(setq elst (cdr elst))
)
(cons (cdar new) (mapcar 'car (cdr new)))
)
Return on selecting a line :
(dxf_min (entget (car (entsel)))) -> ("LINE" 10 11)
-
Nice challenge, Tim. I'm going to bow out of it, but one thing I wanted make note of......
If you are wanting the codes to truly recreate the object, then you should check for the non-existence of any ByLayer type items (such as color & linetype) and include the codes for them, otherwise the Current settings will be used. Also, you may (or may not) want to include any XData, LData, Dictionary entries......
Good Luck and Have fun everyone. :-)
-
I'm a bit confused here. 'Recreate' indicates copy so that would be everything except the handle and ID'd , yes ?
For anyone wanting a jump start on this project have a look for the StdLib project produced by Reini Urban
et al circa 2000.
Enjoy.
-
gile,
That is close to what I did, except I was taking items away, and testing it it could be made, while you are adding them and checking if they could be made. It looks like your way is better as mine relates items that don't need to be there.
Nice challenge, Tim. I'm going to bow out of it, but one thing I wanted make note of......
If you are wanting the codes to truly recreate the object, then you should check for the non-existence of any ByLayer type items (such as color & linetype) and include the codes for them, otherwise the Current settings will be used. Also, you may (or may not) want to include any XData, LData, Dictionary entries......
Good Luck and Have fun everyone. :-)
I'm a bit confused here. 'Recreate' indicates copy so that would be everything except the handle and ID'd , yes ?
For anyone wanting a jump start on this project have a look for the StdLib project produced by Reini Urban
et al circa 2000.
Enjoy.
Jeff and Kerry,
I guess my use of 'recreate' was the wrong choice of words. The way I would use this routine would be to find out what is the minimum dxf codes needed to create an entity. If I didn't know what the minimum codes were for a line, how would I know how to create one using 'entmake'? That is the way I would use this code. Sorry for creating any confusion.
Here was my attempt.
(defun MinEntmake (EntData)
(foreach lst EntData
(setq EntData (cdr EntData))
(if (entmake EntData)
(entdel (entlast))
(if (not (equal (car lst) 5))
(setq EntData (append EntData (list lst)))
)
)
)
EntData
)
-
If I didn't know what the minimum codes were for a line, how would I know how to create one using 'entmake'?
Perhaps (quick stab) --
(defun MinDxfDef ( ename / result temp )
;; will create crap if the current or parent
;; layer of the candidate entity is locked
(foreach pair (setq result (entget ename))
(if (entmake (setq temp (vl-remove pair result)))
(progn (entdel (entlast))(setq result temp))
result
)
)
)
(progn (mapcar 'print (MinDxfDef (car (entsel)))) (princ))
Select object: <selects line thusly>
(0 . "LINE")
(10 3.479 4.617 0.0)
(11 8.513 6.236 0.0)
:)
-
Thanks Michael. I was thinking of trying 'vl-remove' but thought it might be slow, but then again with the size of the data being used would it really be noticable.
-
Always good to keep performance in mind. I just figured there was little change this would end up in a iteration loop executed thousands of times, but maybe I assume too much.
:)
-
Always good to keep performance in mind. I just figured there was little change this would end up in a iteration loop executed thousands of times, but maybe I assume too much.
:)
No, you were right. I would use it once at a time. Learning what is needed to create a view through code, or create a line if not known, so I could code it correctly.