Entmod/entupd question

Hi Michael
I'm not sure, but nobody replied yet....
In snipped-for-privacy@news1.newsguy.com snipped-for-privacy@dont.try (Michael Bulatovich) wrote to all:
here you setq ent to be only what you extracted and discarded the rest. Sometimes it is allowed to give ACAD an incomplete list of an entity for entupd and let ACAD do the rest. In your case I don't see how even the entity-name is preserved, so how should acad be able to deal with it in entmod?
I never relied on ACAD completing my work, so I always subst in the complete list returned by entget before entmod and entupd.
OTOH I never dealt with group code 48 and don't have an ACAD handy, so maybe I'm besides the point. I'm off for a week.
Cheers,
Herbert
Reply to
Herbert Koenig
Loading thread data ...
I'm writing a routine where I want to pull one item out of the entdata of an
object. Here's the pertinent section of code:
(while (>= counter 0)
(setq item (ssname ss counter))
(setq ent (entget item))
(setq backhalf(cdr(member (assoc 48 ent) ent)))
(setq fronthalf(reverse(cdr(member(assoc 48 (reverse ent))(reverse
ent)))))
(setq ent (append fronthalf backhalf))
(entmod ent)(entupd item)
(setq counter (1- counter))
)
When I test ent before and after the entmod, it looks right. When I test the
entdata of item before and after the entupd, it is the same(unchanged).
The routine exits as if done, but the object on screen is unchanged, and
when I use (entget(car(entsel))) at the command prompt and pick the object,
the list is unchanged.
What am I doing wrong?
Reply to
Michael Bulatovich
Some ideas....
If the code is not modifying a subentity such as an attribute, there should not be a need for 'entupd'. Does it work without that? If an entity with nested items, a 'regen' may be needed.
Reply to
Carl AK
Every other line but this make sense ;
(setq fronthalf(reverse(cdr(member(assoc 48 (reverse ent))(reverse ent)))))
It is quite smart to reverse the list and find the front with Reverse --- but didn't you use Cdr once to much , --- in the fronthalf ?
Reply to
per.corell
Sorry wrong word --- it's quite smart to find the front of the list with Reverse and _then Member .
Reply to
per.corell
Hi Herbert,
As I said before, when I check ent before and after the entmod call it look *right*, but when I check the entdata of the object before and after the entmod, it remains the same.
The point of this code *is* to remove (assoc 48) which is LTSCALE override for the item, and return its LTSCALE to the default, which is no (assoc 48). The enitity should survive this 'pruning' because the presence of this item is optional.
The entity name is preserved as the first member in "fronthalf".
Can you use subst with null?
Reply to
Michael Bulatovich
HiHo; I don't know where Herbert got the group code 48 but if that is the entity my bible says Re: "entmod","you cannot use any linetype...... not already defined in the current drawing session". Found on page 13-22 in "Autolisp Programming". Would the "subst" function work?
Reply to
Jiro
Yeah, the entupd was a "Hail Mary". It didn't work without it, so I tried adding it. I also tried a regen.
Reply to
Michael Bulatovich
It seems to work, when I monitor the value of fronthalf, and then the new appended ent. Where it seems to fail is at the entmod.
Reply to
Michael Bulatovich
Thanks, I made that up myself. I am astounded at the lack of facility in handling lists in LISP before all those nifty vl-functions came along. I couldn't remember the usual way of deleting an item form the list except by using CDR , which got me halfway there until I remembered REVERSE...
If nobody knows why this doesn't work, I'm going to try deleting the original, and creating a new item from what appears to be a valid list.
Reply to
Michael Bulatovich
Group 48 is LTSCALE override. The absence of the group indicates no override: line displayed as per system variable. ( A bit like no color being BYLAYER.)
As background, elsewhere in the routine, I have added a group 48 (matching the value extracted from another item picked by user) to the data of an entity that had none (giving it an override), *AND* substituted a group 48 of a different value in an entity that had one.
ENTMOD works fine in that section (excerpted below):
(while (>= counter 0) (setq item (ssname ss counter)) (setq ent (entget item)) (if (assoc 48 ent) (progn (setq ent (subst lts (assoc 48 ent) ent)) (entmod ent) ;modify the ent (setq counter (1- counter)) );end then progn (progn (setq ltss(list lts)) (setq ent (append ent ltss)) (entmod ent) ;modify the ent (setq counter (1- counter)) );end else progn );end if )
Reply to
Michael Bulatovich
Maybe I should try animal sacrifice, or a little dance...?
Reply to
Michael Bulatovich
Well, I tried that and it worked.
It proves the list was fine, but that the ENTMOD was not working for some reason. I can live with this approach, but would like to understand ENTMOD better...
Reply to
Michael Bulatovich
LtsMatch.LSP now on the website if anyone's interested.
Reply to
Michael Bulatovich
All the code I've been doing recently uses the SUBST command. This is pulled out of one of the functions:
(setq new (entget (entlast)) ; the string will be the last entity new (subst (cons 1 a) (assoc 1 new) new) ; set up to change the text in the ; database ) (entmod new) ; update the database
This is for the text string (in an on-screen editor), but the principal should work for code 48.
Martin
Michael Bulatovich wrote:
Reply to
Martin Shoemaker
The difference here is that I want no code 48 to remain, so the question is can SUBST substitute a null for a dotted pair. I haven't tried it since I got it to work with ENTDEL and ENTMAKE.
Reply to
Michael Bulatovich
I am sorry to say that I don't compleatly agrea with that --- but it is also becaurse the way I try to use Lisp ; for me the ideal Lisp program ,is one compressed line of code , that "make the answer" . What I mean is, that you maby added one to many "Reverse or "Cdr and overlook that. I find there are plenty --- and with the enginous use you display, splitting the entity list reversing it to remove a particular sub-list with "Member that's just perfect , the "old" Lisp functions seem to handle things in a way that would be quite boring with any other processing languages . ------ Just one line of code emagine how many lines that would take with any other language.
------ maby I shuld add that this also mean ,that it often are easier to rewrite a function compleatly instead of trying to remember why you coded it like that 2 years ago ;))
Reply to
per.corell

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.