while/if?
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
while/if?

 
Post new topic   Reply to topic    CADForums.net Forum Index -> AutoCAD
Author Message
chuck
Guest





Posted: Fri Oct 22, 2004 10:53 am    Post subject: while/if? Reply with quote

Hi everyone Iv'e written a lisp routine which might seem primitive to some.
This is what I want to happen.... I want the routine to perform an operation
"txtfr" which will format the text of all dimension entities on the drawing
to a customized font and then exit the progar "quietly". As it stands every
time I rum the program I will get an error message following the execution
of the program. The program works perfectly the first time, with the
exception of the error message, but on subsequent attempts, I have to run
the program twice in order for it to take effect. I am quite new at using
the "while" and "if" logic combination in a program and am wondering if
there might be something wrong here. Can anyone help?


;chdim written by Chuck Fluri 20/10/04
;converts dimension text to a formatted text string

(defun c:chdim ()
(setq ent1 (entnext)) ;sets the entity to the first entity in the
table
(while (/= nil ent1) ;checks to see if the end of the table has been
reached
(progn (setq entype (cdr (assoc 0 entlist))
;defines the entity type
)
(if (= entype "DIMENSION") ;if the entity is a dimension...
(progn
(setq entlist (entget ent1)
;creates a list of the entity codes
dimlen (cdr (assoc 42 entlist))
;retrieves the dimension length
reptxt (txtfr dimlen)
;converts the dimension length to a formatted string
arxcode (cons 1 reptxt)
;constructs the new code for the dimension string
) ;setq
(setq entlist (subst arxcode (assoc 1 entlist) entlist)
;replaces the formated string code for the the existing one
) ;setq
(entmod entlist) ;updates the data base
) ;progn
) ;if
(setq ent1 (entnext ent1) ;procceed to the next entity
entlist (entget ent1) ;constructs the new list of codes
) ;setq
) ;progn
) ;while
(setq ent1 nil) ;sets the entity to nil
(princ) ;exit quietly
) ;defun

Back to top
Jeff
Guest





Posted: Fri Oct 22, 2004 5:25 pm    Post subject: Re: while/if? Reply with quote

Hi Chuck,
A couple small things and one BIG reccomendation......
The small things.....I believe your error is coming from this portion:
(setq ent1 (entnext ent1) ;;procceed to the next entity
entlist (entget ent1))

You are using (entget), which is normally fine except when the end of the
database is reached and (entnext) returns nil. Relocating the (entget) would
solve this.
Next, why change the values to a string? If the conversion function is just
appending text to the value then you can do that AND keep the associative
values by using prefixes & suffixes.

Now the big thing......(entnext)'ing through a drawing is NOT the way to do
what you want. Look into Filtered Selection Sets! This will dramatically
reduce the time it takes to run your routine. An example:

(set counter -1)
(if (setq ss (ssget "x" '((0 . "DIMENSION")(1 . ""))));;gets ALL dimensions
that do not use the text override
(progn
(while (< (setq counter (1+ counter)) (sslength ss));keep going while
counter is less than ss length
(setq ent (ssname ss counter))
;;do your stuff with the dimension......
);while
);progn
);if

HTH,
--
Jeff
check out www.cadvault.com
"chuck" <chuck@nospam.wo> wrote in message
news:k72ed.2782$0v6.979@read1.cgocable.net...
Quote:
Hi everyone Iv'e written a lisp routine which might seem primitive to
some.
This is what I want to happen.... I want the routine to perform an
operation
"txtfr" which will format the text of all dimension entities on the
drawing
to a customized font and then exit the progar "quietly". As it stands
every
time I rum the program I will get an error message following the execution
of the program. The program works perfectly the first time, with the
exception of the error message, but on subsequent attempts, I have to run
the program twice in order for it to take effect. I am quite new at using
the "while" and "if" logic combination in a program and am wondering if
there might be something wrong here. Can anyone help?
Back to top
chuck
Guest





Posted: Wed Oct 27, 2004 8:06 am    Post subject: Re: while/if? Reply with quote

Hi Jeff I've used your suggestion regarding filtered selection sets and it
works like a charm! Thankyou. The reason I'm not appending the dimension
text is because what I'm trying to accomplish here is to use a custom font
whereby the fraction portion of the dimension text is stacked wit no bar and
no inch marker. Also the romansf font is much nicer than the AutoCAD stacked
font.

I have one more question, when I attempt to filter ot the radial and
diametric dimensions using association 100, I get the wrong result. It seems
there are 3 associated values for 100 in a dimension and it's using the
first one which is ACDBEntity. How do I get it to recognize the association
I want? as you can tell I'm quite new to entity handling and so far am
entirely self-taught. I appreciate any help. Thanks
"Jeff" <miff@sonic451.net> wrote in message
news:pT7ed.470$_3.8241@typhoon.sonic.net...
Quote:
Hi Chuck,
A couple small things and one BIG reccomendation......
The small things.....I believe your error is coming from this portion:
(setq ent1 (entnext ent1) ;;procceed to the next entity
entlist (entget ent1))

You are using (entget), which is normally fine except when the end of the
database is reached and (entnext) returns nil. Relocating the (entget)
would
solve this.
Next, why change the values to a string? If the conversion function is
just
appending text to the value then you can do that AND keep the associative
values by using prefixes & suffixes.

Now the big thing......(entnext)'ing through a drawing is NOT the way to
do
what you want. Look into Filtered Selection Sets! This will dramatically
reduce the time it takes to run your routine. An example:

(set counter -1)
(if (setq ss (ssget "x" '((0 . "DIMENSION")(1 . ""))));;gets ALL
dimensions
that do not use the text override
(progn
(while (< (setq counter (1+ counter)) (sslength ss));keep going while
counter is less than ss length
(setq ent (ssname ss counter))
;;do your stuff with the dimension......
);while
);progn
);if

HTH,
--
Jeff
check out www.cadvault.com
"chuck" <chuck@nospam.wo> wrote in message
news:k72ed.2782$0v6.979@read1.cgocable.net...
Hi everyone Iv'e written a lisp routine which might seem primitive to
some.
This is what I want to happen.... I want the routine to perform an
operation
"txtfr" which will format the text of all dimension entities on the
drawing
to a customized font and then exit the progar "quietly". As it stands
every
time I rum the program I will get an error message following the
execution
of the program. The program works perfectly the first time, with the
exception of the error message, but on subsequent attempts, I have to
run
the program twice in order for it to take effect. I am quite new at
using
the "while" and "if" logic combination in a program and am wondering if
there might be something wrong here. Can anyone help?



Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> AutoCAD All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB