Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Append" Pitfalls?

24 REPLIES 24
Reply
Message 1 of 25
Anonymous
216 Views, 24 Replies

"Append" Pitfalls?

Hi All,

I'm using the following to set and unset entity visibility. I am not
checking for a pre-existing code 60. I'm just doing an unconditional append.
It appears to be working perfectly, but I'm wondering if cheating is going
to get me into trouble. Any opinions?

Thanks,

Gary

(setq defdat (append defdat (list (cons 60 1))))
(entmod defdat)
24 REPLIES 24
Message 21 of 25
Anonymous
in reply to: Anonymous

You're both welcome. Glad to help. Have a nice weekend.

Doug
Message 22 of 25
Anonymous
in reply to: Anonymous

> It can be even shorter. There is no need to check for the existence of
> the field. See Doug's reposnse below.
>

Frank, this is not fully true:

1 - yes I do not need check for the existence of the field

2 - in some occurrences I need to use the subst method
to override the field

(maybe when the field is not optional?)

Marco

see:
>>> subst
Comando: !e_data
((-1 . ) (0 . "MTEXT") (330 . 40080c10>)
(5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
40.0)
(41 . 0.0) (71 . 4) (72 . 1) (1 . "OLDSTRING") (7 . "STANDARD") (210 0.0 0.0
1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
1.0))

Comando: (entmod (subst (cons 1 "NEWSTRING") (assoc 1 e_data) e_data))
((-1 . ) (0 . "MTEXT") (330 . 40080c10>)
(5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
40.0)
(41 . 0.0) (71 . 4) (72 . 1) (1 . "NEWSTRING") (7 . "STANDARD") (210 0.0 0.0
1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
1.0))

Comando: (entget (cdr (assoc -1 e_data)))
((-1 . ) (0 . "MTEXT") (330 . 40080c10>)
(5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
40.0)
(41 . 0.0) (71 . 4) (72 . 1) (1 . "NEWSTRING") (7 . "STANDARD") (210 0.0 0.0
1.0) (11 1.0 0.0 0.0) (42 . 264.0) (43 . 40.1421) (50 . 0.0) (73 . 1) (44 .
1.0))

>>> (1 . "NEWSTRING")


>>> (list ename field)
Comando: !e_data
((-1 . ) (0 . "MTEXT") (330 . 40080c10>)
(5 . "BB6E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 100.0 0.0) (40 .
40.0)
(41 . 0.0) (71 . 4) (72 . 1) (1 . "OLDSTRING") (7 . "STANDARD") (210 0.0 0.0
1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
1.0))

Comando: (entmod (list (assoc -1 e_data) '(1 . "NEWSTRING") ))
((-1 . ) (1 . "NEWSTRING"))

Comando: (entget (cdr (assoc -1 e_data)))
((-1 . ) (0 . "MTEXT") (330 . 40080c10>)
(5 . "BB6E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 100.0 0.0) (40 .
40.0)
(41 . 0.0) (71 . 4) (72 . 1) (1 . "") (7 . "STANDARD") (210 0.0 0.0 1.0) (11
1.0 0.0 0.0) (42 . 0.0) (43 . 0.0) (50 . 0.0) (73 . 1) (44 . 1.0))

>>> (1 . "")
Message 23 of 25
Anonymous
in reply to: Anonymous

Hmmm..
Yes Mtext does seem problematic. But the short way works with many
other entity types (line, circle, arc, insert, text...), and not just with
optional data fields. Start points, insertion points, rotation angles, layers,
text data in text entities.... can all be changed by creating a short entity info
list containing just the reference ename field and the data to change.

(entmod (list (cons -1 ename)(cons 1 "newtext"))) when applied to an mtext
entity results in an mtext entity with a blank text field (1 . ""). AutoCAD
apparently ignores the new text specification.

Seems like an AutoCAD bug to me. But Mtext entities are complex and there
is an interrelationship between many of the fields. I created
a program to convert text entities to mtext entities and even needed to use the
100 fields AcDbEntity and AcDbMtext to get it to work.

I guess there are exceptions to every rule.

Doug

"Marc'Antonio Alessi" wrote in message news:EC220C76B737A01C300BE334304D0FD2@in.WebX.maYIadrTaRb...
> > It can be even shorter. There is no need to check for the existence of
> > the field. See Doug's reposnse below.
> >
>
> Frank, this is not fully true:
>
> 1 - yes I do not need check for the existence of the field
>
> 2 - in some occurrences I need to use the subst method
> to override the field
>
> (maybe when the field is not optional?)
>
> Marco
>
> see:
> >>> subst
> Comando: !e_data
> ((-1 . ) (0 . "MTEXT") (330 . > 40080c10>)
> (5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
> "$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
> 40.0)
> (41 . 0.0) (71 . 4) (72 . 1) (1 . "OLDSTRING") (7 . "STANDARD") (210 0.0 0.0
> 1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
> 1.0))
>
> Comando: (entmod (subst (cons 1 "NEWSTRING") (assoc 1 e_data) e_data))
> ((-1 . ) (0 . "MTEXT") (330 . > 40080c10>)
> (5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
> "$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
> 40.0)
> (41 . 0.0) (71 . 4) (72 . 1) (1 . "NEWSTRING") (7 . "STANDARD") (210 0.0 0.0
> 1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
> 1.0))
>
> Comando: (entget (cdr (assoc -1 e_data)))
> ((-1 . ) (0 . "MTEXT") (330 . > 40080c10>)
> (5 . "BB6D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
> "$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 50.0 0.0) (40 .
> 40.0)
> (41 . 0.0) (71 . 4) (72 . 1) (1 . "NEWSTRING") (7 . "STANDARD") (210 0.0 0.0
> 1.0) (11 1.0 0.0 0.0) (42 . 264.0) (43 . 40.1421) (50 . 0.0) (73 . 1) (44 .
> 1.0))
>
> >>> (1 . "NEWSTRING")
>
>
> >>> (list ename field)
> Comando: !e_data
> ((-1 . ) (0 . "MTEXT") (330 . > 40080c10>)
> (5 . "BB6E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
> "$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 100.0 0.0) (40 .
> 40.0)
> (41 . 0.0) (71 . 4) (72 . 1) (1 . "OLDSTRING") (7 . "STANDARD") (210 0.0 0.0
> 1.0) (11 1.0 0.0 0.0) (42 . 252.0) (43 . 40.5563) (50 . 0.0) (73 . 1) (44 .
> 1.0))
>
> Comando: (entmod (list (assoc -1 e_data) '(1 . "NEWSTRING") ))
> ((-1 . ) (1 . "NEWSTRING"))
>
> Comando: (entget (cdr (assoc -1 e_data)))
> ((-1 . ) (0 . "MTEXT") (330 . > 40080c10>)
> (5 . "BB6E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
> "$LAY_TEXT_NORM") (62 . 253) (100 . "AcDbMText") (10 0.0 100.0 0.0) (40 .
> 40.0)
> (41 . 0.0) (71 . 4) (72 . 1) (1 . "") (7 . "STANDARD") (210 0.0 0.0 1.0) (11
> 1.0 0.0 0.0) (42 . 0.0) (43 . 0.0) (50 . 0.0) (73 . 1) (44 . 1.0))
>
> >>> (1 . "")
>
>
>
>
>
>
Message 24 of 25
Anonymous
in reply to: Anonymous

In article ,
Marc'Antonio Alessi wrote:
> 2 - in some occurrences I need to use the subst method
> to override the field

When you use the (subst ...) method, you force AutoCAD to go through
the entire list to find the matching item and create a new list with
that item replaced. Then the (entmod ...) must go through the entire
list code by code, deciding if the code can be changed and, if so,
changing it.

If you just use entmod (list (assoc 1 e_data) (cons 1 "NEWSTRING"))
then you make one smaller list very quickly and (entmod ...) has much
less work to do.

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services
Message 25 of 25
Anonymous
in reply to: Anonymous

> If you just use entmod (list (assoc 1 e_data) (cons 1 "NEWSTRING"))
> then you make one smaller list very quickly and (entmod ...) has much
> less work to do.

I know and agree, but it is important to know if there are
limitations and which they are.

Marco

Comando: !a
((-1 . ) (0 . "MTEXT") (330 . 4007fcf8>)
(5 . "52") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"$0__TEXT_NORM")
(100 . "AcDbMText") (10 0.0 0.0 0.0) (40 . 2.0) (41 . 0.0) (71 . 1) (72 . 5)
(1
. "NEWSTRING") (7 . "Standard") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 .
17.3333) (43 . 2.0) (50 . 0.0) (73 . 1) (44 . 1.0))

Copyright © 1989-2001 by R. Robert Bell.
(bench '(entmod_subst entmod_ename) (list a) 1000)

(defun entmod_subst (e_data)
(entmod (subst (cons 1 "NEWSTRING") (assoc 1 e_data) e_data))
)

(defun entmod_ename (e_data)
(entmod (list (assoc -1 e_data) '(1 . "NEWSTRING")))
)

ENTMOD_SUBST
Elapsed: 420
Average: 0.42

ENTMOD_ENAME
Elapsed: 130
Average: 0.13


"Jon Fleming" ha scritto nel messaggio
news:VA.00000fbb.05c3847b@fleming-group.com...
> In article ,
> Marc'Antonio Alessi wrote:
> > 2 - in some occurrences I need to use the subst method
> > to override the field
>
> When you use the (subst ...) method, you force AutoCAD to go through
> the entire list to find the matching item and create a new list with
> that item replaced. Then the (entmod ...) must go through the entire
> list code by code, deciding if the code can be changed and, if so,
> changing it.
>
> If you just use entmod (list (assoc 1 e_data) (cons 1 "NEWSTRING"))
> then you make one smaller list very quickly and (entmod ...) has much
> less work to do.
>
> jrf
> Member of the Autodesk Discussion Forum Moderator Program
> Please do not email questions unless you wish to hire my services
>
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost