Loading missing line styles

Loading missing line styles

Anonymous
Not applicable
308 Views
13 Replies
Message 1 of 14

Loading missing line styles

Anonymous
Not applicable
We have custom line styles in a file mspiso.lin and have left acadiso.lin
untouched. We also have a lisp routine that creates layers by reading lines
in a text file. The lisp fails as soon as it encounters a custom line style
that is not already loaded in the drawing.

Is there a way to have the line style loaded on demand? How do you determine
if a specific line style has been loaded in a drawing already? I would
prefer to try loading the line style only if the layer creation fails since
the custom line styles only occur on 1% of the layers used.

Thanks in advance,
Allen
0 Likes
309 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
(if (not (tblsearch "LTYPE" "MyLType"))
(command "._linetype" "_l" "MyLType" "MSPIso.lin" "")
)

Do this *before* creating the layer. It won't load the linetype unless it is
missing.

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Allen Humphries" wrote in message
news:2563EEF29288FEED38AD82E32E168812@in.WebX.SaUCah8kaAW...
| We have custom line styles in a file mspiso.lin and have left acadiso.lin
| untouched. We also have a lisp routine that creates layers by reading
lines
| in a text file. The lisp fails as soon as it encounters a custom line
style
| that is not already loaded in the drawing.
|
| Is there a way to have the line style loaded on demand? How do you
determine
| if a specific line style has been loaded in a drawing already? I would
| prefer to try loading the line style only if the layer creation fails
since
| the custom line styles only occur on 1% of the layers used.
|
| Thanks in advance,
| Allen
|
0 Likes
Message 3 of 14

Anonymous
Not applicable
Allen,

Try this. Its part of a larger program called Autolay[2]. It makes layers
and sets their properties according to your layer standards. It also
switches to the appropriate layers when it encounters "*hatch", "vport",
"text" or "dim*" commands. Want me to repost the whole thing (it'll require
a bit of teewking to work for you)?
--
Eric S. eschneider@jensenprecast.com

;;;returns ActiveX object if exist, else nil
(defun al:exist (object item / rslt)
(if
(not
(vl-catch-all-error-p
(setq rslt
(vl-catch-all-apply 'vla-item
(list object item)
);trap error
);end setq
);return T if successful, else nil
);end not
rslt; return object or nil
);end if
);end defun

;;;attempts to load linetype if not loaded
;;;returns linetype object name if loaded else nil
(defun al:loadltype (name fname /)
(if
(not (al:exist ltypes name));linetype is not loaded
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-load (list ltypes name fname);load it, unfortunately vla-load
returns nil on success or error on fail instead of linetype object
);trap error if load fails
);return T if successful, else nil
);end if
(al:exist ltypes name);return linetype object if exists, else nil
);end defun
0 Likes
Message 4 of 14

Anonymous
Not applicable
Beat you!

I thought about providing the VL method, but Allen didn't specify his
AutoCAD version...

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Eric Schneider" wrote in message
news:CCEAC244FDF09F46650421C746358B77@in.WebX.SaUCah8kaAW...
| Allen,
|
| Try this. Its part of a larger program called Autolay[2]. It makes layers
| and sets their properties according to your layer standards. It also
| switches to the appropriate layers when it encounters "*hatch", "vport",
| "text" or "dim*" commands. Want me to repost the whole thing (it'll
require
| a bit of teewking to work for you)?
| --
| Eric S. eschneider@jensenprecast.com
|
| ;;;returns ActiveX object if exist, else nil
| (defun al:exist (object item / rslt)
| (if
| (not
| (vl-catch-all-error-p
| (setq rslt
| (vl-catch-all-apply 'vla-item
| (list object item)
| );trap error
| );end setq
| );return T if successful, else nil
| );end not
| rslt; return object or nil
| );end if
| );end defun
|
| ;;;attempts to load linetype if not loaded
| ;;;returns linetype object name if loaded else nil
| (defun al:loadltype (name fname /)
| (if
| (not (al:exist ltypes name));linetype is not loaded
| (vl-catch-all-error-p
| (vl-catch-all-apply
| 'vla-load (list ltypes name fname);load it, unfortunately
vla-load
| returns nil on success or error on fail instead of linetype object
| );trap error if load fails
| );return T if successful, else nil
| );end if
| (al:exist ltypes name);return linetype object if exists, else nil
| );end defun
|
0 Likes
Message 5 of 14

Anonymous
Not applicable
Beat me! Beat me! Oh it feels so ... OOPS! wrong group.
: )
--
Eric S. eschneider@jensenprecast.com
0 Likes
Message 6 of 14

Anonymous
Not applicable
Sorry for the missing info. I am using AD2, soon to install AD2i.

It will take a little while to understand the code. I've never used vlisp
before.

I'm a little concerned about the overhead of executing the search for the
linetype before creating each layer. Could I trap the error when the
linetype is not found, load it, then create the layer properly and resume
the loop?

I appreciate the help.

Allen

"R. Robert Bell" wrote in message
news:8BD7378FFC80D279CA6A24750E02A9F2@in.WebX.SaUCah8kaAW...
> Beat you!
>
> I thought about providing the VL method, but Allen didn't specify his
> AutoCAD version...
>
> --
> R. Robert Bell, MCSE
> Xtending the Power
> www.acadx.com
>
> "Eric Schneider" wrote in message
> news:CCEAC244FDF09F46650421C746358B77@in.WebX.SaUCah8kaAW...
> | Allen,
> |
> | Try this. Its part of a larger program called Autolay[2]. It makes
layers
> | and sets their properties according to your layer standards. It also
> | switches to the appropriate layers when it encounters "*hatch", "vport",
> | "text" or "dim*" commands. Want me to repost the whole thing (it'll
> require
> | a bit of teewking to work for you)?
> | --
> | Eric S. eschneider@jensenprecast.com
> |
> | ;;;returns ActiveX object if exist, else nil
> | (defun al:exist (object item / rslt)
> | (if
> | (not
> | (vl-catch-all-error-p
> | (setq rslt
> | (vl-catch-all-apply 'vla-item
> | (list object item)
> | );trap error
> | );end setq
> | );return T if successful, else nil
> | );end not
> | rslt; return object or nil
> | );end if
> | );end defun
> |
> | ;;;attempts to load linetype if not loaded
> | ;;;returns linetype object name if loaded else nil
> | (defun al:loadltype (name fname /)
> | (if
> | (not (al:exist ltypes name));linetype is not loaded
> | (vl-catch-all-error-p
> | (vl-catch-all-apply
> | 'vla-load (list ltypes name fname);load it, unfortunately
> vla-load
> | returns nil on success or error on fail instead of linetype object
> | );trap error if load fails
> | );return T if successful, else nil
> | );end if
> | (al:exist ltypes name);return linetype object if exists, else nil
> | );end defun
> |
>
0 Likes
Message 7 of 14

Anonymous
Not applicable
You could, I suppose, but the overhead you are worried about is negligible.
After all, how many linetypes does the typical drawing have? 5-20?

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Allen Humphries" wrote in message
news:49A27F1C7ACADC306B7784D4B9460FB9@in.WebX.SaUCah8kaAW...
| Sorry for the missing info. I am using AD2, soon to install AD2i.
|
| It will take a little while to understand the code. I've never used vlisp
| before.
|
| I'm a little concerned about the overhead of executing the search for the
| linetype before creating each layer. Could I trap the error when the
| linetype is not found, load it, then create the layer properly and resume
| the loop?
|
| I appreciate the help.
|
| Allen
|
| "R. Robert Bell" wrote in message
| news:8BD7378FFC80D279CA6A24750E02A9F2@in.WebX.SaUCah8kaAW...
| > Beat you!
| >
| > I thought about providing the VL method, but Allen didn't specify his
| > AutoCAD version...
| >
| > --
| > R. Robert Bell, MCSE
| > Xtending the Power
| > www.acadx.com
| >
| > "Eric Schneider" wrote in message
| > news:CCEAC244FDF09F46650421C746358B77@in.WebX.SaUCah8kaAW...
| > | Allen,
| > |
| > | Try this. Its part of a larger program called Autolay[2]. It makes
| layers
| > | and sets their properties according to your layer standards. It also
| > | switches to the appropriate layers when it encounters "*hatch",
"vport",
| > | "text" or "dim*" commands. Want me to repost the whole thing (it'll
| > require
| > | a bit of teewking to work for you)?
| > | --
| > | Eric S. eschneider@jensenprecast.com
| > |
| > | ;;;returns ActiveX object if exist, else nil
| > | (defun al:exist (object item / rslt)
| > | (if
| > | (not
| > | (vl-catch-all-error-p
| > | (setq rslt
| > | (vl-catch-all-apply 'vla-item
| > | (list object item)
| > | );trap error
| > | );end setq
| > | );return T if successful, else nil
| > | );end not
| > | rslt; return object or nil
| > | );end if
| > | );end defun
| > |
| > | ;;;attempts to load linetype if not loaded
| > | ;;;returns linetype object name if loaded else nil
| > | (defun al:loadltype (name fname /)
| > | (if
| > | (not (al:exist ltypes name));linetype is not loaded
| > | (vl-catch-all-error-p
| > | (vl-catch-all-apply
| > | 'vla-load (list ltypes name fname);load it, unfortunately
| > vla-load
| > | returns nil on success or error on fail instead of linetype object
| > | );trap error if load fails
| > | );return T if successful, else nil
| > | );end if
| > | (al:exist ltypes name);return linetype object if exists, else nil
| > | );end defun
| > |
| >
|
0 Likes
Message 8 of 14

Anonymous
Not applicable
I would that that were the case. Our current layer list is approaching 300
layers. Admittedly, not all are used in any particular drawing but all are
created consistently and are restored en masse after being purged. When a
drawing is complete, it can easily contain 100 layers.

Yt,
Allen
"R. Robert Bell" wrote in message
news:C81C8E65D849DD6BEF727879D6C3FFCE@in.WebX.SaUCah8kaAW...
> You could, I suppose, but the overhead you are worried about is
negligible.
> After all, how many linetypes does the typical drawing have? 5-20?
0 Likes
Message 9 of 14

Anonymous
Not applicable
I think your first problem to solve is your drawing organization...I try to
guess where people use so many layers for one drawing. At 10 years ago we
were using a single sheet...with a single color...
Does anybody know that story about 3 men lost in the jungle?...They were
freezing, surrounded by the dry wood...

"Allen N. Humphries" escreveu na mensagem
news:B5EB6D52666752B26AE9B75AA1FB0272@in.WebX.SaUCah8kaAW...
> I would that that were the case. Our current layer list is approaching 300
> layers. Admittedly, not all are used in any particular drawing but all are
> created consistently and are restored en masse after being purged. When a
> drawing is complete, it can easily contain 100 layers.
>
> Yt,
> Allen
> "R. Robert Bell" wrote in message
> news:C81C8E65D849DD6BEF727879D6C3FFCE@in.WebX.SaUCah8kaAW...
> > You could, I suppose, but the overhead you are worried about is
> negligible.
> > After all, how many linetypes does the typical drawing have? 5-20?
>
>
0 Likes
Message 10 of 14

Anonymous
Not applicable
Note that I said *linetypes*, not layers...

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Allen N. Humphries" wrote in message
news:B5EB6D52666752B26AE9B75AA1FB0272@in.WebX.SaUCah8kaAW...
| I would that that were the case. Our current layer list is approaching 300
| layers. Admittedly, not all are used in any particular drawing but all are
| created consistently and are restored en masse after being purged. When a
| drawing is complete, it can easily contain 100 layers.
|
| Yt,
| Allen
| "R. Robert Bell" wrote in message
| news:C81C8E65D849DD6BEF727879D6C3FFCE@in.WebX.SaUCah8kaAW...
| > You could, I suppose, but the overhead you are worried about is
| negligible.
| > After all, how many linetypes does the typical drawing have? 5-20?
|
|
0 Likes
Message 11 of 14

Anonymous
Not applicable
Sorry Robert I'm not understanding something here. I thought your routine
checked to see if the linetype was loaded for each layer created. i.e. 300
checks for 300 layers x # of linetypes. I'm hoping to check only on a
failure when a custom line style is not found, probably 1 failure/check in
100 layers created. Typical drawing have up to 6 linetypes, site plans maybe
12.

Silvio, I'm not looking for a long discourse on layer management. Suffice it
to say that we use the same model for site plan, 1:250 key plans, 1:100
layout plans, 1:50 floor plans, 1:100 reflected ceiling plans, 1:50
reflected ceiling plans and as backgrounds for the consultants. This
increases the number of layers so we have the flexibility to turn layers on
and off as needed and to change linetype or colour (pen weight) to suit.

The trade-off is more layers for less duplication of linework.

Yt,
Allen
"R. Robert Bell" wrote in message
news:14C4D51AB9A2C614CDD9393DD615CD45@in.WebX.SaUCah8kaAW...
> Note that I said *linetypes*, not layers...
>
> --
> R. Robert Bell, MCSE
> Xtending the Power
> www.acadx.com
>
> "Allen N. Humphries" wrote in message
> news:B5EB6D52666752B26AE9B75AA1FB0272@in.WebX.SaUCah8kaAW...
> | I would that that were the case. Our current layer list is approaching
300
> | layers. Admittedly, not all are used in any particular drawing but all
are
> | created consistently and are restored en masse after being purged. When
a
> | drawing is complete, it can easily contain 100 layers.
> |
> | Yt,
> | Allen
> | "R. Robert Bell" wrote in message
> | news:C81C8E65D849DD6BEF727879D6C3FFCE@in.WebX.SaUCah8kaAW...
> | > You could, I suppose, but the overhead you are worried about is
> | negligible.
> | > After all, how many linetypes does the typical drawing have? 5-20?
> |
> |
>
0 Likes
Message 12 of 14

Anonymous
Not applicable
Valid question, so here is an extreme example (3,000 "layers"):

(setq StartTime (getvar "Millisecs"))
(repeat 3000
(if (not (tblsearch "LTYPE" "Hidden"))
(command "._linetype" "_l" "Hidden" "ACAD.lin" "")
)
)
(princ (strcat "\nElapsed time: " (itoa (- (getvar "Millisecs") StartTime))
" millisecs."))

Returns:

Elapsed time: 1055 millisecs.

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Allen Humphries" wrote in message
news:E79341A84C68467B5C0216B82ADCC6F7@in.WebX.SaUCah8kaAW...
| Sorry Robert I'm not understanding something here. I thought your routine
| checked to see if the linetype was loaded for each layer created. i.e. 300
| checks for 300 layers x # of linetypes. I'm hoping to check only on a
| failure when a custom line style is not found, probably 1 failure/check in
| 100 layers created. Typical drawing have up to 6 linetypes, site plans
maybe
| 12.
|
| Silvio, I'm not looking for a long discourse on layer management. Suffice
it
| to say that we use the same model for site plan, 1:250 key plans, 1:100
| layout plans, 1:50 floor plans, 1:100 reflected ceiling plans, 1:50
| reflected ceiling plans and as backgrounds for the consultants. This
| increases the number of layers so we have the flexibility to turn layers
on
| and off as needed and to change linetype or colour (pen weight) to suit.
|
| The trade-off is more layers for less duplication of linework.
|
| Yt,
| Allen
| "R. Robert Bell" wrote in message
| news:14C4D51AB9A2C614CDD9393DD615CD45@in.WebX.SaUCah8kaAW...
| > Note that I said *linetypes*, not layers...
| >
| > --
| > R. Robert Bell, MCSE
| > Xtending the Power
| > www.acadx.com
| >
| > "Allen N. Humphries" wrote in message
| > news:B5EB6D52666752B26AE9B75AA1FB0272@in.WebX.SaUCah8kaAW...
| > | I would that that were the case. Our current layer list is approaching
| 300
| > | layers. Admittedly, not all are used in any particular drawing but all
| are
| > | created consistently and are restored en masse after being purged.
When
| a
| > | drawing is complete, it can easily contain 100 layers.
| > |
| > | Yt,
| > | Allen
| > | "R. Robert Bell" wrote in message
| > | news:C81C8E65D849DD6BEF727879D6C3FFCE@in.WebX.SaUCah8kaAW...
| > | > You could, I suppose, but the overhead you are worried about is
| > | negligible.
| > | > After all, how many linetypes does the typical drawing have? 5-20?
| > |
| > |
| >
|
0 Likes
Message 13 of 14

Anonymous
Not applicable
Allen Humphries wrote:
>
> Sorry Robert I'm not understanding something here. I thought your routine
> checked to see if the linetype was loaded for each layer created. i.e. 300
> checks for 300 layers x # of linetypes. I'm hoping to check only on a
> failure when a custom line style is not found, probably 1 failure/check in
> 100 layers created. Typical drawing have up to 6 linetypes, site plans maybe
> 12.

I'm really not sure what is the problem here, since
AutoCAD already checks for the existence of a linetype
anytime you use it.

There is little overhead required to look up a linetype
in the linetype table. You are making an issue out of a
matter of milliseconds, and those few milliseconds are
totally inperceptible.

For each layer you define, just do a (tblsearch) for
the linetype, and if it returns nil, then you need to
load the linetype.

And, since that is really the only choice you have
(aside from preloading the linetypes into the template
file and then purging the unused ones), there's little
point to bickering over a few milliseconds.

While performance can matter for some things, for a
drawing setup procedure that isn't used frequently,
even a few extra seconds is irrelevant.

--

Checkout the AcadX(tm) ActiveX Extension Library at:

http://www.caddzone.com/acadx/acadx.htm

/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/
0 Likes
Message 14 of 14

Anonymous
Not applicable
Thanks to all for your input.

Robert & Tony,
I wasn't trying to quibble, I just didn't know what order of magnitude we
were talking about and doing something once rather than 300 times appeared
at first glance to have some payback. Since the lookup is so fast, it
doesn't make sense worrying about it. As soon as my production deadline
passes I'll implement the suggestions and make everyone here happier. Thanks
again.

Yt,
Allen
0 Likes