Jump to content

Recommended Posts

Posted
  On 2/3/2025 at 11:50 PM, BIGAL said:

This is where I started there is info out there but a bit hard to find. The zip has lisp and vba example it is just in one file for my convenience as I cut and paste from it.

 

https://www.cadtutor.net/forum/topic/79565-autocad-use-libreoffice-instead-of-excel/page/3/
 

Get and Put data into Libreoffice Calc — BricsCAD Forum

https://forum.bricsys.com/discussion/38699/get-and-put-data-into-libreoffice-calc?utm_source=community-search&utm_medium=organic-search&utm_term=libre

Look at Tim_n post.

 

The main thing is start here.

 

(setq oServiceManager (vlax-get-or-create-object "com.sun.star.ServiceManager"))

 

 

Best to reply to my original post rather than here.

 Put back into my To do list.

 

Libre.zip 2.13 kB · 1 download

Expand  

I have to find time to get back to work on that.

Posted (edited)

Hi @GLAVCVS
Thanks for lisp, few issues I've noticed while testing that LINETYPEs are not changing at all
Above Lisp routine unable to change the linetypes?

The code's tested in between two drawings, "A" and "B."

In drawing "A,"  (which i gave earlier), the custom linetypes are loaded. The Lisp successfully changes the color and lineweight, but not the linetype.

In drawing "B," (attached below) the custom linetypes are not loaded. The Lisp fails completely, throwing a "bad order function: COMMAND" error.
 

this is DWG A where line types loaded not not changed

 

 

this is DWG B attched below, Error Shows "Error: bad order function: COMMAND"

 

Edited by CADChaser
Posted (edited)

@CADChaser If you create a template ( dws ) with all your layers, linetypes etc, you can use the OOTB STANDARDS command to check if a drawing is in compliance:

image.png.a4a8ad090d2e2fc4e73a264a0b92c395.png

image.png.d213630d0e345daf4ff9d68783979175.png

 

That being said, since you have a template now simply start all new drawings with it.

Edited by ronjonp
Posted (edited)

So far, I've reviewed and added only what is necessary to make your code work in the drawing/template you attached.
The part of your code that tries to load the linetypes is not good. When the linetypes are already loaded in the drawing, that code is not executed and goes unnoticed. But when the linetypes are not in the drawing, as in the last drawing you attached, when executed they generate an error.
So I had to replace that part of the code as well.
But then another problem appears: the linetype file you attached ('STD Linetypes.lin') does not contain the linetypes that appear in the 'standard' list.
I'm starting to get the feeling that I'm working for you 😅😅
I'm going to attach the result of my latest modifications.
I think that should be enough.

 

(defun c:SetLayerProperties (/		       *error*
			     layer-name	       standards
			     log-missing       missing-linetypes
			     linetype-map      layer-props
			     layer-name-matches
			     apply-standards cad reg
			    )

  ;; Error handler
  (defun *error* (msg)
    (if	msg
      (princ (strcat "\nError: " msg))
    )
    (if	(and missing-linetypes (/= (length missing-linetypes) 0))
      (progn
	(princ "\n\nMissing Linetypes:")
	(mapcar	'(lambda (x) (princ (strcat "\n- " x)))
		missing-linetypes
	)
      )
    )
    (princ "\nRoutine ended.")
    (princ)
  )

  ;; Layer standards: (LayerName Color Linetype LineWeight Scale)
;;;  (setq	standards
;;;	 '(
;;;	   ("E-CENTERLINES" 253 "CENTER2" acLineWeight050 1.00)
;;;	   ("E-BUILDING" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-CURB" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-DITCH" 253 "DITCHLINE" acLineWeight018 0.75)
;;;	   ("E-DRAINAGE PIPE" 253 "Continuous" acLineWeight030 1.00)
;;;	   ("E-DRIVE WAY" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-ELECTRIC" 253 "UNDER_ELEC" acLineWeight018 0.75)
;;;	   ("E-ELECTRIC STRUCTURE" 253 "UNDER_ELEC" acLineWeight050 1.00)
;;;	   ("E-EOP" 253 "Continuous" acLineWeight020 1.00)
;;;	   ("E-FENCE" 253 "Fence1" acLineWeight018 0.75)
;;;	   ("E-FIBER-OH" 253 "Overhead" acLineWeight018 0.75)
;;;	   ("E-FIBER-UG" 253 "UNDER_FIBER" acLineWeight018 0.75)
;;;	   ("E-GAS" 253 "UNDER_GAS" acLineWeight018 0.75)
;;;	   ("E-GUARDRAILS" 253 "GUARD_RAIL" acLineWeight002 0.20)
;;;	   ("E-GUTTER" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-PARKING LOT" 250 "Continuous" acLineWeight050 1.00)
;;;	   ("E-PAVEMENT MARKINGS" 253 "Continuous" acLineWeight009 1.00)
;;;	   ("E-ROAD SIGN" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-ROW" 8 "RIGHTOFWAY" acLineWeight035 0.70)
;;;	   ("E-ROW Lot line" 253 "PROPERTYLINE" acLineWeight030 0.70)
;;;	   ("E-ROW VDOT" 2 "RIGHTOFWAY" acLineWeight070 0.70)
;;;	   ("E-SANITARY-SEWER" 253 "UNDER_SAN" acLineWeight018 0.75)
;;;	   ("E-SIDEWALK" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-STORM-SEWER" 253	"UNDER_STORMDRAIN" acLineWeight018 0.75)
;;;	   ("E-TACTILE PAVING" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-TELEPHONE" 253 "UNDER_TELE" acLineWeight018 0.75)
;;;	   ("E-TELEPHONE GUY WIRE" 253 "Continuous" acLineWeight018 0.75)
;;;	   ("E-TRANS TRACKS" 253 "TRACKS" acLineWeight050 1.00)
;;;	   ("E-TREELINE" 253 "Continuous" acLineWeight050 1.00)
;;;	   ("E-UTILTY POLE" 250 "Continuous" acLineWeight050 1.00)
;;;	   ("E-WATER" 253 "UNDER_WATER" acLineWeight018 0.75)
;;;	   ("EX CONC DITCHES"	  253
;;;	    "EX. CONC. DITCH_LINE"
;;;	    acLineWeight018	  0.75
;;;	   )
;;;	   ("LEGEND" 7 "Continuous" acLineWeight050 1.00)
;;;	   ("P-CONDUIT AERIAL" 10 "DASHED" acLineWeight007 0.20)
;;;	   ("P-CONDUIT UG" 10 "Continuous" acLineWeight070 1.00)
;;;	  )
;;;  )
  

  (setq	standards
	 '(
	   ("CENTERLINE" 253 "CENTER2" 0 1.00)
	   ("BUILDING" 253 "Continuous" 0 1.00)
	   ("CURB" 253 "Continuous" 0 1.00)
	   ("DITCH" 253 "DITCHLINE" 0 0.75)
	   ("PIPE" 253 "Continuous" 0.30 1.00)
	   ("DRIVE" 253 "Continuous" 0 1.00)
	   ("ELECTRIC" 253 "UNDER_ELEC" 0 0.75)
	   ("ELECTRIC STRUCTURE" 253 "UNDER_ELEC" 0 1.00)
	   ("EOP" 253 "Continuous" 0.20 1.00)
	   ("FENCE" 253 "Fence1" 0 0.75)
	   ("FIBER-OH" 253 "Overhead" 0 0.75)
	   ("FIBER-UG" 253 "UNDER_FIBER" 0 0.75)
	   ("GAS" 253 "UNDER_GAS" 0 0.75)
	   ("GUARDRAIL" 253 "GUARD_RAIL" 0 0.20)
	   ("GUTTER" 253 "Continuous" 0 1.00)
	   ("PARKING LOT" 250 "Continuous" 0 1.00)
	   ("PAVEMENT" 253 "Continuous" 0.09 1.00)
	   ("SIGN" 253 "Continuous" 0 1.00)
	   ("E-ROW" 8 "RIGHTOFWAY" 0.35 0.70)
	   ("E-ROW Lot line" 253 "PROPERTYLINE" 0.30 0.70)
	   ("DOT" 2 "RIGHTOFWAY" 0.70 0.70)
	   ("SANITARY" 253 "UNDER_SAN" 0 0.75)
	   ("SIDEWALK" 253 "Continuous" 0 1.00)
	   ("STORM" 253	"UNDER_STORMDRAIN" 0 0.75)
	   ("TACTILE" 253 "Continuous" 0 1.00)
	   ("TELEPHONE" 253 "UNDER_TELE" 0 0.75)
	   ("TRACK" 253 "TRACKS" 0 1.00)
	   ("TREE" 253 "Continuous" 0 1.00)
	   ("POLE" 250 "Continuous" 0 1.00)
	   ("WATER" 253 "UNDER_WATER" 0 0.75)
	   ("CONC" 253 "EX. CONC. DITCH_LINE" 0 0.75)
	   ("LEGEND" 7 "Continuous" 0 1.00)
	   ("P-CONDUIT AERIAL" 10 "DASHED" 0.70 0.20)
	   ("P-CONDUIT UG" 10 "Continuous" 0.70 1.00)
	  )
  )




  ;; Initialize variables
  (setq missing-linetypes '())
  (setq	linetype-map
	 (mapcar '(lambda (x) (list (car x) (nth 2 x)))
		 standards
	 )
  )

  ;; Load required linetypes, log missing
  (mapcar
    '(lambda (lt)
       (if (not (tblsearch "LTYPE" lt))
	 (progn
	   (if (not (vl-catch-all-error-p
		      (vl-catch-all-apply
			'command
			(list "._linetype" "load" lt "")
		      )
		    )
	       )
	     (princ (strcat "\nLoaded linetype: " lt))
	     (if (not (member lt missing-linetypes))
	       (setq missing-linetypes (cons lt missing-linetypes))
	     )
	   )
	 )
       )
     )
    (mapcar 'caddr standards)
  )

  (vlax-for layer (vla-get-layers
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
    (setq layer-name (vla-get-name layer))
    (if	(setq layer-props (assoc (vla-get-name layer) standards))
      (setq layer-props (list layer-props))
      (foreach x standards
	(if (wcmatch (strcase layer-name) (strcat "*" (strcase (car x)) "*"))
	  (setq layer-props (cons x layer-props))
	)
      )
    )
    (if	layer-props
      (progn
	(if (> (length layer-props) 1)
	  (progn
	    (alert
	      (strcat
		"There is more than 1 layer record in the \'standard\' list that matches \'"
		(vla-get-name layer)
		"\'\nThe layer will be updated to the parameters of the first match in the list"
	      )
	    )
	    (foreach reg layer-props
	      (setq cad (if cad
			  (strcat cad ", " (car reg))
			  (strcat "\n*** WARNING: multiple matches>>> BaseNames: " (car reg))
			)
	      )
	    )
	    (princ (strcat cad " ---> Layer: " layer-name))
	    (setq layer-props (car layer-props) cad nil)
	  )
	  (setq layer-props (car layer-props))
	)
	(vla-put-color layer (nth 1 layer-props))
	(if (not (vl-catch-all-error-p
		   (vl-catch-all-apply
		     'vla-put-linetype
		     (list layer (nth 2 layer-props))
		   )
		 )
	    )
	  (vla-put-linetype layer "Continuous")
	)
	(vla-put-lineweight layer (* (nth 3 layer-props) 100))
	(princ
	  (strcat "\nLayer \'"
		  (vla-get-name layer)
		  "\' has been updated to \'standard\' value \'"
		  (car layer-props)
		  "\'"
	  )
	)
      )
    )
    (setq layer-props nil)
  )


  ;; Report missing linetypes
  (if missing-linetypes
    (progn
      (princ "\n\nMissing Linetypes:")
      (mapcar '(lambda (lt) (princ (strcat "\n- " lt)))
	      missing-linetypes
      )
    )
  )
  (princ "\n\nRoutine completed successfully.")
  (princ)
)

 

Edited by GLAVCVS
Posted

As Ronjonp says, it's best to use the first drawing you attached ("Test Drawing 2.dwg") as a template.
It will make things much easier.

Posted
  On 2/4/2025 at 5:25 PM, ronjonp said:

@CADChaser If you create a template ( dws ) with all your layers, linetypes etc, you can use the OOTB STANDARDS command to check if a drawing is in compliance:
(images here)

That being said, since you have a template now simply start all new drawings with it.


hello there,
Thanks for your suggestions. I've tried that, but it doesn't automatically change layer properties. also Layer Translator works, but manually mapping each file is too time-consuming and inefficient.

Posted

Dear Glavcvs,

 

Thank you so much for your help! I really appreciate it, and I promise I'm not trying to make you do all the work. Your support means a lot to me! 🙇‍♀️
 

Just to update you, after testing the new code, the linetypes still aren't changing to the correct standard. The 'STD Linetypes.lin' file is missing only the ditch linetype, but other line types are available but not changing. Rest is working absolutely fine and I'm really happy for it, also now I'm starting to think that loading a custom linetype with Lisp might not be possible.

Posted (edited)

"loading a custom linetype with Lisp might not be possible." look again at my post on page 1 it checks does linetype exist if not then load. Ok if must also do another defun using read-line and see if the linetype name is in the custom.lin, if not display a message. The wcmatch function checks the string for a matching text string. So if found set a variable to "Yes" if "No" then dont run the load part. 

 

As already suggested we copied a dwg into our dwt so all the correct line types were already there to be used. A few seconds task.

Edited by BIGAL
Posted

Loading custom linetypes is very possible .. assuming the *.lin is in the support path this function should work. Of course the lists need to be updated for the OP.

  (defun _loadlt (/ ex v va)
    (setq va (mapcar 'getvar (setq v '(cmdecho expert))))
    (mapcar 'setvar v '(0 5))
    (foreach lt	(if (= 0 (getvar 'measurement))
		  '("acad.lin" "custom.lin" "idt.lin")
		  '("acadiso.lin" "idtiso.lin")
		)
      (and (findfile lt) (command "-linetype" "L" "*" lt ""))
    )
    (mapcar 'setvar v va)
    (princ)
  )

 

Posted

Dear all,
After many attempts (25+), and with the help of AI, I've finally arrived at a working LISP routine (below). I'm incredibly grateful for all your time and effort in helping me. To make this thread easier to navigate for others in the future, could you please remove the older attachments?


Thank you @GLAVCVS @BIGAL @ronjonp
 

LAYSET Tool Features:


✅ Auto-sets layer properties (color/linetype/weight)
✅ Smart LIN file loading if missing
✅ Wildcard layer matching
✅ You can modify as per your needs

 

(defun c:Layset (/ *error* layer-name standards missing-linetypes layer-props selectedLinFile linetype-list found-lt)

  ;; Error handler
  (defun *error* (msg)
    (if msg (princ (strcat "\nError: " msg)))
    (princ "\nRoutine ended.")
    (princ)
  )

  ;; Layer standards (include PARCEL entry)
  (setq standards
    	 '(
	   ("CENTERLINE" 253 "CENTER2" 0 1.00)
	   ("BUILDING" 253 "Continuous" 0 1.00)
	   ("CURB" 253 "Continuous" 0 1.00)
	   ("DITCH" 253 "DITCHLINE" 0 0.75)
	   ("PIPE" 253 "Continuous" 0.30 1.00)
	   ("DRIVE" 253 "Continuous" 0 1.00)
	   ("ELECTRIC" 253 "UNDER_ELEC" 0 0.75)
	   ("ELECTRIC STRUCTURE" 253 "UNDER_ELEC" 0 1.00)
	   ("EOP" 253 "Continuous" 0.20 1.00)
	   ("FENCE" 253 "Fence1" 0 0.75)
	   ("FIBER-OH" 253 "Overhead" 0 0.75)
	   ("FIBER-UG" 253 "UNDER_FIBER" 0 0.75)
	   ("GAS" 253 "UNDER_GAS" 0 0.75)
	   ("GUARDRAIL" 253 "GUARD_RAIL" 0 0.20)
	   ("GUTTER" 253 "Continuous" 0 1.00)
	   ("PARKING LOT" 250 "Continuous" 0 1.00)
	   ("PAVEMENT" 253 "Continuous" 0.09 1.00)
	   ("SIGN" 253 "Continuous" 0 1.00)
	   ("E-ROW" 8 "RIGHTOFWAY" 0.35 0.70)
	   ("PARCEL" 253 "PROPERTYLINE" 0.30 0.70)  ; New entry for parcel layers
	   ("E-ROW Lot line" 253 "PROPERTYLINE" 0.30 0.70)
	   ("DOT" 2 "RIGHTOFWAY" 0.70 0.70)
	   ("SANITARY" 253 "UNDER_SAN" 0 0.75)
	   ("SIDEWALK" 253 "Continuous" 0 1.00)
	   ("STORM" 253	"UNDER_STORMDRAIN" 0 0.75)
	   ("TACTILE" 253 "Continuous" 0 1.00)
	   ("TELEPHONE" 253 "UNDER_TELE" 0 0.75)
	   ("TRACK" 253 "TRACKS" 0 1.00)
	   ("TREE" 253 "Continuous" 0 1.00)
	   ("POLE" 250 "Continuous" 0 1.00)
	   ("WATER" 253 "UNDER_WATER" 0 0.75)
	   ("CONC" 253 "EX. CONC. DITCH_LINE" 0 0.75)
	   ("LEGEND" 7 "Continuous" 0 1.00)
	   ("P-CONDUIT AERIAL" 10 "DASHED" 0.70 0.20)
	   ("P-CONDUIT UG" 10 "Continuous" 0.70 1.00)
	  )
  )

  ;; Phase 1: Identify missing linetypes
  (setq linetype-list (mapcar 'caddr standards))
  (setq missing-linetypes
    (vl-remove-if '(lambda (x) (tblsearch "LTYPE" x)) linetype-list)
  )

  ;; Phase 2: Load missing linetypes (single prompt)
  (if missing-linetypes
    (progn
      (princ (strcat "\nMissing linetypes: " (vl-princ-to-string missing-linetypes)))
      (setq selectedLinFile (getfiled "Select LIN File" "acad.lin" "LIN" 4))
      (if selectedLinFile
        (foreach lt missing-linetypes
          (if (vl-catch-all-error-p
                (vl-catch-all-apply 'vla-load
                  (list (vla-get-linetypes 
                          (vla-get-activedocument (vlax-get-acad-object)))
                        lt
                        selectedLinFile
                      )
                )
              )
            (setq found-lt (cons lt found-lt))
          )
        )
      )
      ;; Update missing linetypes list after loading attempt
      (setq missing-linetypes
        (vl-remove-if '(lambda (x) (tblsearch "LTYPE" x)) missing-linetypes)
      )
    )
  )

  ;; Phase 3: Apply layer properties
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (setq layer-name (strcase (vla-get-name layer)))
    (if (setq layer-props
            (car
              (vl-sort
                (vl-remove-if-not
                  '(lambda (x)
                     (wcmatch layer-name (strcat "*" (strcase (car x)) "*"))
                   )
                  standards
                )
                '(lambda (a b) (> (strlen (car a)) (strlen (car b))))
              )
            )
          )
      (progn
        (vla-put-color layer (nth 1 layer-props))
        (if (tblsearch "LTYPE" (nth 2 layer-props))
          (vla-put-linetype layer (nth 2 layer-props))
          (princ (strcat "\nSkipped linetype for " layer-name " - linetype missing"))
        )
        (vla-put-lineweight layer (* (nth 3 layer-props) 100))
        (princ (strcat "\nProcessed layer: " (vla-get-name layer)))
      )
    )
  )

  ;; Final reporting
  (if missing-linetypes
    (progn
      (princ "\n\nPersistent missing linetypes:")
      (foreach lt missing-linetypes (princ (strcat "\n- " lt)))
      (princ "\n\nCheck for:")
      (princ "\n1. Exact linetype name match (case-sensitive)")
      (princ "\n2. Valid definition in LIN file")
    )
    (princ "\nAll required linetypes loaded successfully")
  )
  (princ)
)




linload.thumb.png.0895977d848db77a6df040b7a3e73a7e.pngbfpic.thumb.png.564b1242712720076a3f1ce7eb7d4ca7.png

Posted

You can edit any post so remove old code I normally keep the code box but refer to where the new code is. Just pick the ... top right.

Posted
  On 2/8/2025 at 10:53 PM, CADChaser said:

Estimados todos,
después de muchos intentos (más de 25) y con la ayuda de la IA, finalmente logré una rutina LISP funcional (a continuación). Estoy increíblemente agradecido por todo el tiempo y esfuerzo que dedicaron a ayudarme. Para que este hilo sea más fácil de navegar para otros en el futuro, ¿podrían eliminar los archivos adjuntos más antiguos?


Gracias@GLAVCVS @BIGAL @ronjonp
 

Características de la herramienta LAYSET:


✅Establece automáticamente las propiedades de capa (color/tipo de línea/grosor)
✅Carga inteligente de archivo LIN si falta
✅Coincidencia de capa con comodín
✅Puede modificarlo según sus necesidades

 










linload.thumb.png.0895977d848db77a6df040b7a3e73a7e.pngbfpic.thumb.png.564b1242712720076a3f1ce7eb7d4ca7.png

Expand  

 

👏👏👏

 

  • Thanks 1

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...