Author Topic: Wildcard loading of linetypes ...  (Read 2333 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Wildcard loading of linetypes ...
« 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Wildcard loading of linetypes ...
« Reply #1 on: May 09, 2006, 05:53:10 PM »
Well I liked it. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Wildcard loading of linetypes ...
« Reply #2 on: May 09, 2006, 06:25:18 PM »
Always the gentleman and scholar, thank you Alan!

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst