Author Topic: (Challenge) Get the min. dxf codes needed to create an entity of the same type  (Read 10356 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
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.
« Last Edit: July 06, 2007, 06:03:04 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) Get the minimum dxf codes needed to recreate an object
« Reply #1 on: July 06, 2007, 04:54:08 PM »
Here is what mine returns.  Just as an example.
Quote
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))
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: (Challenge) Get the minimum dxf codes needed to recreate an object
« Reply #2 on: July 06, 2007, 05:14:57 PM »
Hi, here's my contribution

Code: [Select]
(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)
Speaking English as a French Frog

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: (Challenge) Get the minimum dxf codes needed to recreate an object
« Reply #3 on: July 06, 2007, 05:32:53 PM »
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. :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Get the minimum dxf codes needed to recreate an object
« Reply #4 on: July 06, 2007, 05:52:00 PM »
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.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) Get the minimum dxf codes needed to recreate an object
« Reply #5 on: July 06, 2007, 06:00:48 PM »
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.
Code: [Select]
(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
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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) --

Code: [Select]
(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)

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.