TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MP on May 08, 2006, 01:26:13 PM

Title: Wildcard loading of linetypes ...
Post by: MP on May 08, 2006, 01:26:13 PM
A friend of mine just asked me how to do it, this is one simplistic answer --

Code: [Select]
(defun LoadLineTypes ( lineTypeSpec lineTypeFileName / result )
    (if (findfile lineTypeFileName)
        (vl-catch-all-apply
           '(lambda ( )
                (vla-load
                    (vla-get-linetypes
                        (vla-get-activedocument
                            (vlax-get-acad-object)
                        )
                    )
                    lineTypeSpec
                    lineTypeFileName
                )
                (setq result t)
            )   
        )
    )   
    result
)

If the the linetype already exists in the drawing or the specified linetype doesn't exist in the linetype definition file or said file doesn't exist / is corrupt the function will return nil. Accordingly, the function will return t on a successful load. As such, the caller may wish to some some preprocessing / prequalification before invoking if they wish for the calling logic to branch appropriately.

While one could be more ambitious and perform all the noted scan / prequalifications I opted to keep it lean and mean per the original inquirey.


Example use --

Code: [Select]
(LoadLineTypes "continuous" "acad.lin")
Returns nil because "continuous" is already defined in drawing.

Assuming linetype "hidden" doesn't exist in drawing and is defined in acad.lin --

Code: [Select]
(LoadLineTypes "hidden" "acad.lin")
Returns t.

A second call --

Code: [Select]
(LoadLineTypes "hidden" "acad.lin")
Returns nil because the "hidden" linetype is already defined.

If all linetypes are purged from drawing, then this call (which uses the wild carding) --

Code: [Select]
(LoadLineTypes "*" "acad.lin")
Returns t the first time it's invoked, nil thereafter (all things remaining constant) for the reasons noted above.

Cheers.
Title: Re: Wildcard loading of linetypes ...
Post by: CAB on May 09, 2006, 05:53:10 PM
Well I liked it. 8-)
Title: Re: Wildcard loading of linetypes ...
Post by: MP on May 09, 2006, 06:25:18 PM
Always the gentleman and scholar, thank you Alan!

:)