Jump to content

load linetypes from lisp...help


Recommended Posts

Posted

 

hello:

 

any routine to load linetypes from lisp?

 

thanks

Posted

A complex example
Creates a shp file of the shape for a complex linetype
Compile this file
Creates the linetype .lin model
Makes the linetype table
Load this type of line into the current drawing
Linetype is available in the drawing

 

((lambda ( / f_shp f_lin doc)
	(if (not (findfile "rond_plein.shp"))
		(progn
			(setq f_shp (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\rond_plein.shp") "w"))
			(write-line "*128,66,RONDPLEIN" f_shp)
			(write-line "2,3,10,010,1,10,(1,000),2,010,1,10,(2,000),2,010,1,10,(3,000),2,010,1,10," f_shp)
			(write-line "(4,000),2,010,1,10,(5,000),2,010,1,10,(6,000),2,010,1,10,(7,000),2,010,1,10," f_shp)
			(write-line "(8,000),2,010,1,10,(9,000),2,010,1,10,(10,000),2,3,10,0" f_shp)
			(close f_shp)
		)
	)
	(command "_.compile" (strcat (getvar "ROAMABLEROOTPREFIX") "support\\rond_plein.shp"))
	(if (not (tblsearch "STYLE" ""))
		(entmakex
			'(
				(0 . "STYLE")
				(100 . "AcDbSymbolTableRecord")
				(100 . "AcDbTextStyleTableRecord")
				(2 . "")
				(70 . 1)
				(40 . 0.0)
				(41 . 1.0)
				(50 . 0.0)
				(71 . 0)
				(42 . 2.5)
				(3 . "rond_plein.shx")
				(4 . "")
			 )
		)
	)
	(entmake
		(list
			'(0 . "LTYPE")
			'(100 . "AcDbSymbolTableRecord")
			'(100 . "AcDbLinetypeTableRecord")
			'(2 . "DotsLine")
			'(70 . 0)
			'(3 . "pointillé shx . . . .")
			'(72 . 65)
			'(73 . 2)
			'(40 . 1.0)
			'(49 . 1.0)
			'(74 . 4)
			'(75 . 128)
			(CONS 340 (TBLOBJNAME "STYLE" ""))
			'(46 . 0.1)
			'(50 . 0.0)
			'(44 . 0.0)
			'(45 . 0.0)
			'(49 . 0.0)
			'(74 . 0)
		)
	)
	(if (not (findfile "DotsLine.lin"))
		(progn
			(setq f_lin (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\DotsLine.lin") "w"))
			(write-line "*DotsLine,cloture shx . . . ." f_lin)
			(write-line "A,1,[RONDPLEIN,rond_plein.shx,x=0,s=.1],0" f_lin)
			(close f_lin)
		)
	)
	(setq doc (vla-get-activedocument (vlax-get-acad-object)))
	(if
		(and
			(not
				(vlax-for item (vla-get-linetypes doc)
					(if (= (strcase (vla-get-name item)) (strcase "DotsLine")) T)
				)
			)
			(vl-catch-all-error-p
				(vl-catch-all-apply
					'vla-load
					(list (vla-get-Linetypes doc) "DotsLine" "DotsLine.lin")
				)
			)
		)
		nil
		T
	)
	(princ "\nCréation de Type de Ligne \"DotsLine\" effectué!")
	(prin1)
))

 

  • Thanks 1
Posted

maybe this

 

; By alanh

(defun loadLinetype (doc LineTypeName FileName)
  (if (and
        (not (existLinetype doc LineTypeName))
        (vl-catch-all-error-p
          (vl-catch-all-apply
            'vla-load
            (list
              (vla-get-Linetypes doc)
              LineTypeName
              FileName
            )
          )
        )
      )
    nil
    T
  )
)

(defun existLinetype (doc LineTypeName / item loaded)
  (vlax-for item (vla-get-linetypes doc)
    (if (= (strcase (vla-get-name item)) (strcase LineTypeName))
      (setq loaded T)
    )
  )
)

;load missing linetypes
;;; returns: T if loaded else nil
(loadLinetype doc "Fence" "custom.lin")
(loadLinetype doc "Tree" "custom.lin")
(loadLinetype doc "Water_main" "custom.lin")
(loadLinetype doc "Gas_main"  "custom.lin")
(loadLinetype doc "Sewer_main" "custom.lin")

 

Posted
2 hours ago, aridzv said:

@leonucadomi

Hi.

I've attached 2 files:

  1. llt_Autocad.lsp for autocad
  2. lt_Bricscad.lsp for bricscad

see if it helps...

aridzv

llt_Bricscad.lsp 241 B · 0 downloads llt_Autocad.lsp 245 B · 1 download

 

I might be tempted to combine these to a single -capture everything- LISP using something like 

 

(if (findfile "ISO..lin")

  (setq linefile "Iso.lin")

  (setq linefile "acadiso.lin")

)

 

fewer files to manage.

  • Agree 1
  • Thanks 1
Posted (edited)
1 hour ago, Steven P said:

 

I might be tempted to combine these to a single -capture everything- LISP using something like 

 

(if (findfile "ISO..lin")

  (setq linefile "Iso.lin")

  (setq linefile "acadiso.lin")

)

 

fewer files to manage.

True,I agree.

but usually people either work with one or the other, and only rarely do they work simultaneously with both.

Edited by aridzv
  • Like 1
Posted

@Steven P

can you help me with a way to run this lisp on startup (not load - that is obvious...)?

I've searched for S::STARTUP but could'nt find a way...

Posted

Perhaps edit or make acaddoc.lsp file, which is a LISP file, loaded at each drawing - it is associated with the s:startup stuff too. The internet will help here? If this file exists it is loaded automatically.

 

You could save your load linetype LISP in a trusted location folder and in the acaddoc.lsp file include the line / command (loadlinetype) - or whatever your LISP routine is

Or if you want to save the file somewhere else, use something like also in the acaddoc.lsp file:

(load "C:\\Users\\MyFilePAth\\loadlines.lsp" "loadlines Failed to Load") ;;Using full path with double '\' and the file name of your LISP file

and then as above (loadlinetype) command.

 

That should do it. I tend to put my LISPs in the startup suit but if you reload a LISP file anything in there that runs automatically will run again (for example, I have one that sets the snaps as I like, but if I change them while drawings and reload that LISP the snaps go to my default as an example why this approach doesn't work for everything).

Posted (edited)

@Steven P

thanks for the reply.

 

you gave me a few directions...

 

what I did eventualy is this:

  1. I've made sure that the path to the LSP files folder is in the search path.
  2. in bricscad there are 2 types startup files - 
    1. ON_DOC_LOAD.LSP that load for every time a new drawing is opened.
    2. ON_START.LSP that open only once when the software is starting.
  3. I've entered those lines of code to the ON_START.LSP file:
    (load "llt")
    (command "llt")

and thats it...

 

Edited by aridzv
  • Like 1
Posted

Ahh, Bricscad, we use AutoCAD so I didn't know the file names..... thanks, I learn something every day too!!!

  • Thanks 1
Posted (edited)
37 minutes ago, Steven P said:

Ahh, Bricscad, we use AutoCAD so I didn't know the file names..... thanks, I learn something every day too!!!

yes,bricscad...😄

if I remeber correcttly, in autocad the file name for those issues is ACADDOC.lsp.

 

I made one more change, or should I say a more advanced approach:

in the ON_START.LSP file I entered the lisp code without using the lisp name in this way:

 (foreach lt '("Center" "Center2" "Centerx2" "Hidden" "Hidden2" "Hiddenx2")
   (if(not(tblsearch "ltype"lt))
     (command "_.-linetype" "_l" lt "iso.lin" "")
     ); end if
   ); end foreach
 (princ)

what it dose is that the code run on startup, do what it is ment to do (load the line types in this case) but it dosn't create a custom command by the name of LLT and it dosen't load a lisp file in to memory.

Edited by aridzv
  • Like 1
Posted

For years now did not edit acad.lsp etc but rather I have a custom lisp yes its called Autoload.lsp with all my defuns, shortcuts, (AUTOLOAD  etc and yes it works with Bricscad. 

 

Just go to Appload and add it to the startup suite list, then it will autoload and run the lisp on startup.

  • Like 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...