Author Topic: linetype (Load) Question  (Read 3430 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
linetype (Load) Question
« on: November 30, 2004, 03:49:40 PM »
Is there a better way to import linetypes into a drawing?

Code: [Select]

(defun c:Ltest ()
(setvar "cmdecho" 0)
(setq Ldashed "DASHED")
  (if  (not (tblsearch "LTYPE" Ldashed))
  (CREATE_LINETYPES Ldashed)
)
(princ)
)

(defun CREATE_LINETYPES (LineType /)
        (setq LtypePath (findfile "acad.lin"))
  (command "linetype" "load" LineType  LtypePath "" "")
(princ)  
)


This code works but it also says unknown command after it runs. Any ideas? Or better ways of writing?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

David Bethel

  • Swamp Rat
  • Posts: 656
linetype (Load) Question
« Reply #1 on: November 30, 2004, 04:57:29 PM »
Creating LineTypes has never been pretty.

Code: [Select]

(defun SetLType (n d f / lf rf nl)
;;;LineType_Name Descriptor File_name
 (cond ((not (findfile (strcat f ".LIN")))
        (setq lf (open (strcat f ".LIN") "w"))
        (write-line ";; Specialty LineTypes" lf)
        (write-line "" lf)
        (close lf)
        (command "_.LINETYPE" "_Create" n f
                 "----- ----- ----- ----- ----- -----" d ""
                 "_.LINETYPE" "_Load" n f ""))
      ((not (tblsearch "LTYPE" n))
       (setq rf (open (strcat f ".LIN") "r"))
       (while (setq nl (read-line rf))
              (if (wcmatch nl (strcat "`*" n ",*"))
                  (setq ex T)))
       (close rf)
       (if (not ex)
           (command "_.LINETYPE" "_Create" n f
                    "----- ----- ----- ----- ----- -----" d ""))
       (command "_.LINETYPE" "_Load" n f "")))
n)


Usage:

Code: [Select]

  (SetLType "Dash" "1.25,-.25,.25,-.25,.25,-.25" "TEMP1")


-David
R12 Dos - A2K

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
linetype (Load) Question
« Reply #2 on: November 30, 2004, 05:05:28 PM »
Sorry if I was not clear. I need to know if there are easier (better) ways to LOAD linetypes not create them......??
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

David Bethel

  • Swamp Rat
  • Posts: 656
linetype (Load) Question
« Reply #3 on: November 30, 2004, 05:17:02 PM »
First, you need to verify that the linetype file exists in a search path directory.

Second, verify that a linetype definition already exists for the named LType

Third, that the linetype is not already loaded

Otherwise the error message start popping up.

What I posted was a generic loader that insures that the linetype given is indeed loaded, basically no matter what the error is.  

For a standard ACAD LType (SetLType "HIDDEN" "" "ACAD")

-David
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
linetype (Load) Question
« Reply #4 on: November 30, 2004, 06:16:19 PM »
Not sure where I picked this up at:
Code: [Select]
;;;===================================================================;
;;; FIND-LINE-TYPES                                                   ;
;;;-------------------------------------------------------------------;
;;; This searches a linetype collection object and determines if      ;
;;; the linetype is present in the collection.                        ;
;;;                                                                   ;
;;; Note: l-obj is a local variable within the scope of the vlax-for  ;
;;;       function because it is used within a "for" expression       ;
;;;                                                                   ;
;;; Arguments: line-type = A string which denotes the linetype        ;
;;;                        to search for in the line-type-collection  ;
;;;                        argument.                                  ;
;;;            line-type-collection = A vla collection object which   ;
;;;                                   contains the current linetypes  ;
;;;                                   loaded in ACAD.                 ;
;;;                                                                   ;
;;; Returned Value: If the linetype is found a vla linetype object    ;
;;;                 is returned such as:                              ;
;;;                 #<VLA-OBJECT IAcadLineType 03fe0b00>              ;
;;;                 (If the linetype search fails this function       ;
;;;                  returns n(defun TxtStr (x)
;;;                                                                   ;
;;; Usage: (load-line-types "CENTER" "acad.lin")                      ;
;;;===================================================================;
(defun find-line-type (line-type line-type-collection / res)
  (setq line-type (strcase line-type))
  (vlax-for l-obj line-type-collection
    (if (= (strcase (vla-get-name l-obj)) line-type)
      (setq res l-obj)
    )
  )
  res
)
;;;===================================================================;
;;; LOAD-LINE-TYPES                                                   ;
;;;-------------------------------------------------------------------;
;;; This function loads a linetype in to the drawing                  ;
;;;                                                                   ;
;;; Required Functions: find-line-type                                ;
;;;                                                                   ;
;;; Arguments: line-type = A string which denotes the LT to load      ;
;;;            file-name = A string which denotes the LT file to      ;
;;;                        which to load the requested linetype       ;
;;;                                                                   ;
;;; Returned Value:  A vla linetype object objects such as:           ;
;;;                  #<VLA-OBJECT IAcadLineType 03fe0b00>             ;
;;;                                                                   ;
;;; Usage: (load-line-types "CENTER" "acad.lin")                      ;
;;;===================================================================;
(defun load-line-types (line-type file-name / tmp res)
  (if (and (setq tmp (vlax-get-acad-object))
           (setq tmp (vla-get-activedocument tmp))
           (setq tmp (vla-get-linetypes tmp));; linetypes is the last
                                             ;; set and the current
                                             ;; linetype collection
      )
    (if (setq res (find-line-type line-type tmp))
      res
      (progn
       ;; load the linetype
        (vla-load tmp line-type file-name)
       ;; since the vla-load function returns nil
       ;; we force the following function to test if
       ;; the load was successful. If success the
       ;; return the vla linetype object
        (if (vla-item tmp line-type)
          (vla-item tmp line-type)
          ;; Nothing was loaded so we return nil
          nil
        )   ;; _test to see if the line was loaded
      )     ;; evaluate when the linetype is not loaded in acad
    )       ;; end if for check if linetype is loaded
    nil
  )         ;; end if for various calls to ACAD
)
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.

CADaver

  • Guest
linetype (Load) Question
« Reply #5 on: November 30, 2004, 06:24:24 PM »
I just load 'em all.

Code: [Select]
(defun c:ltla ()
(setq ans "")
  (command ".linetype" "l" "*" "e:/programs/ac2002/menus/csa/acad"
    (while (/= (getvar "cmdnames") "")
      (command ans)
    )
  )
)

David Bethel

  • Swamp Rat
  • Posts: 656
linetype (Load) Question
« Reply #6 on: November 30, 2004, 07:00:03 PM »
CADaver,

I agree with you on that approach.

Code: [Select]

(defun c:lltype (/ file rf nl i lt)
 (and (setq file (getfiled "Line File to Edit" "/acad/" "lin" 2))
      (setq rf (open file "r"))
      (princ "\nLoading LineTypes")
      (while (setq nl (read-line rf))
             (if (= "*" (substr nl 1 1))
                 (progn
                   (setq i 1)
                   (while (/= "," (substr nl i 1))
                          (setq i (1+ i)))
                   (setq lt (substr nl 2 (- i 2)))
                   (and (not (tblsearch "LTYPE" lt))
                        (princ (strcat "\rLoading " (strcase lt)))
                        (command "_.LINETYPE" "_Load" lt file "")))))
      (close rf))
 (prin1))


-David
R12 Dos - A2K

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
linetype (Load) Question
« Reply #7 on: December 01, 2004, 07:47:03 AM »
Off the beaten path, but do you have anything that does the same thing for text STYLES?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

David Bethel

  • Swamp Rat
  • Posts: 656
linetype (Load) Question
« Reply #8 on: December 01, 2004, 08:05:25 AM »
Styles are even more of a pain the ltypes to me, Unless you just want the table setup.


Code: [Select]
(defun SetStyle (s)
 (if (or (/= 'STR (type s))
         (and (not (tblsearch "STYLE" s))
              (and (not (findfile (strcat s ".SHX")))
                   (not (findfile (strcat s ".PFB"))))))
      (err (strcat "Cannot Access Text Style " s)))
 (command "_.STYLE" s s)
 (while (> (getvar "CMDACTIVE") 0)
           (command "")))


As you can see from the .PFB file type, this is a very old routine.  -David
R12 Dos - A2K