Author Topic: entmod question  (Read 2247 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
entmod question
« on: July 12, 2007, 10:04:07 AM »
Hey guys (and gals),

How would I replace a known vertex in a polyline (10 x x) in a list using entmod? From what I've read, entmod replaces the first (10 x x) found.

  • (-1 . <Entity name: 7efb4550>)
  • [1] (0 . "LWPOLYLINE")
    [2] (330 . <Entity name: 7efb2d18>)
    [3] (5 . "11A")
    [4] (100 . "AcDbEntity")
    [5] (67 . 0)
    [6] (410 . "Model")
    [7] (8 . "0")
    [8] (100 . "AcDbPolyline")
    [9] (90 . 2)
    [10] (70 . 128)
    [11] (43 . 0.0)
    [12] (38 . 0.0)
    [13] (39 . 0.0)
    [14] (10 6.00998 5.60127)
    [15] (40 . 0.0)
    [16] (41 . 0.0)
    [17] (42 . 0.0)
[18] (10 13.5462 1.82911)
[19] (40 . 0.0)
[20] (41 . 0.0)
[21] (42 . 0.0)
[22] (210 0.0 0.0 1.0)

I would like to replace the bold rather than the (10 6.00998 5.60127) in the [14] spot.

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: entmod question
« Reply #1 on: July 12, 2007, 10:52:38 AM »
You would need to manipulate the list a tidbit to do what you want.

Lets say you you want to replace the second group 10 in a list, you could use something like this

entlist is your lwpolyline list and pnt is your new point

Code: [Select]
(entmod
   (subst
      (cons 10 pnt) ;<-- your new point
      (assoc 10
         (cdr         
            (member
               (assoc 10 entlist)
               entlist
            )
         )
      )
      entlist
   )
)

Now this of course will only change the second group 10, you can make the lisp loop through the entire list of DXF 10 groups by using something like this

"item" is the number of the item you want to retrieve
Code: [Select]
(setq newlist entlist x 0)
(while (< x item)
   (setq newlist
      (cdr
         (member
            (assoc 10 newlist)
          newlist
         )
      )
   )
   (setq x (1+ x))
)

None of this has been tested and it can also be done more efficiently in other manners, but I wanted you to get the understanding of how to accomplish it first.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7529
Re: entmod question
« Reply #2 on: July 12, 2007, 11:02:06 AM »
Thanks Keith...I'll try and get this to work.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: entmod question
« Reply #3 on: July 12, 2007, 11:10:01 AM »
I think you have to use a foreach loop, and test each dxf list to compare it to the one known.  I have run into problems when with trying to substitute associated list when there are real numbers involved.  How I would do it.
Code: [Select]
(foreach lst EntData
 (if (equal lst '(10 x.x x.x x.x) 0.0001)
  (setq NewEntData (append NewEntData (list '(10 x.x x.x x.x))))
  (setq NewEntData (append NewEntData (list lst)))
 )
)
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: entmod question
« Reply #4 on: July 12, 2007, 12:05:27 PM »
Thanks Tim. I think adding that fuzz factor fixed my problems :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: entmod question
« Reply #5 on: July 12, 2007, 12:08:31 PM »
You're welcome.
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: entmod question
« Reply #6 on: July 12, 2007, 02:03:21 PM »
I like it Tim. Here is the mapcar version.
Code: [Select]
(setq elst (mapcar '(lambda (x) (if (equal x OldVal 0.0001) NewVal x)) elst))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: entmod question
« Reply #7 on: July 12, 2007, 02:18:12 PM »
I like it Tim. Here is the mapcar version.
Code: [Select]
(setq elst (mapcar '(lambda (x) (if (equal x OldVal 0.0001) NewVal x)) elst))
I like that version better Alan!  :-)  Must have been to early in the morning on my first post.
Tim

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

Please think about donating if this post helped you.