Jump to content

Recommended Posts

Posted

There are several records in the 'standard' list that contain, for example, the word 'row'. Therefore, when a layer name appears in the drawing with 'row', you must choose 1 of the matches at your discretion.
If you replace the 'vlax-for' with the one I attached, you will understand what I am talking about.

 

  (vlax-for layer (vla-get-layers
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
    (setq layer-name (vla-get-name layer)
	  layer-name (if (= (substr layer-name 2 1) "-") (substr layer-name 3) layer-name)
	  layer-name (vl-string-subst "*,*" "-" layer-name)
	  layer-name (vl-string-subst "*,*" " " layer-name)
    )
    (if (setq layer-props (assoc (vla-get-name layer) standards))
      (setq layer-props (list layer-props))
      (foreach x standards
	(if (wcmatch (car x) (strcat "*" layer-name "*"))
	  (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"))
	    (setq layer-props (car layer-props))
	  )
	  (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)
  )

 

Posted (edited)
  On 2/1/2025 at 4:09 PM, GLAVCVS said:

But: how do you know, from the 'standard' list, which is the base name of the layers with which to compare the existing ones in the drawing to decide which ones to modify?

For example: in the 'standard' list there are several layer names that begin with 'E-' (E-CENTERLINES, for example)
I understand that in these cases I must search for layers whose name matches or contains the string CENTERLINES, BUILDING, CURB....etc)
But in the case of layer names that do not begin with 'E-': how do you decide which string to search for?

 

There should be a unified standard for all other layer names in the 'standard' list.

Expand  



I understand the importance of adhering to standard layer naming conventions. However, certain situations may prevent this. Therefore, I propose a feature to allow pattern-based layer name matching. I've also added a "basename" column for all layers, updated and attached below.


 

Edited by CADChaser
Posted

There are 2 'electric' basenames.
Also, the 'layer' field now becomes unnecessary.

Posted
  On 2/2/2025 at 7:26 AM, GLAVCVS said:

There are 2 'electric' basenames.
Also, the 'layer' field now becomes unnecessary.

 

Yes you are right layer column became useless, we can use base names now and 1 electric basename for all kinda electric named layers, 

Posted (edited)

Also, for these basenames to work as filters, layer names in drawings would have to contain those basenames separated by spaces, dashes, or any other established punctuation marks.
For example, layer names containing 'lot' would have to follow the convention of containing the word 'lot' separately from other longer words: 'E-ROW LOT LINE' but not 'PILOT TUNNEL', for example.

 

If, at some future point, this rule were not followed, the code could produce unexpected results.

Edited by GLAVCVS
Posted

Also: you should make sure that there is no layer name that contains more than 1 'basename'. This is something that happens in the drawing you attached.

Posted
  On 2/2/2025 at 8:31 AM, GLAVCVS said:

Also, for these basenames to work as filters, layer names in drawings would have to contain those basenames separated by spaces, dashes, or any other established punctuation marks.
For example, layer names containing 'lot' would have to follow the convention of containing the word 'lot' separately from other longer words: 'E-ROW LOT LINE' but not 'PILOT TUNNEL', for example.

 

@GLAVCVS
 

I've tried all layer base names and modified again to match our code criteria, I'm really hoping this will not create issues.


I've found few errors in below names and FIXED in attachment.

Row filter has 2 layers with *ROW* in it.

E-ROW

E-ROW LOT LINE

lot filter has 2 layers with *LOT* in it.

E-Parking Lot

E-ROW Lot line

 

Standard layer Properties_02Feb24_Upd.xlsFetching info...

 

image.thumb.png.ccdd0176d43b719b7727fa73bb1341bb.png

Posted

The basename 'electric' keeps being repeated

In any case:
if you want to be able to create consistent code, you will have to establish a rigid rule for naming layers in drawing.
This should be something like: 'basename_' + rest of the name

Posted
  On 2/2/2025 at 10:24 AM, GLAVCVS said:

The basename 'electric' keeps being repeated

In any case:
if you want to be able to create consistent code, you will have to establish a rigid rule for naming layers in drawing.
This should be something like: 'basename_' + rest of the name

 

Im okay if "electric" filter has multiple results, No problem all electric results could be treated as "E-ELECTRIC" standard.

Posted
  On 2/2/2025 at 10:24 AM, GLAVCVS said:

The basename 'electric' keeps being repeated

In any case:
if you want to be able to create consistent code, you will have to establish a rigid rule for naming layers in drawing.
This should be something like: 'basename_' + rest of the name

Dear  @GLAVCVS,

I appreciate your work on this. I'm absolutely fine with the 'ELECTRIC' filter having multiple options, as it should ideally be treated as the standard "E-ELECTRIC." I’ve carefully checked all layer names in CAD basename using the basename filter and have made the necessary modifications in the spreadsheet above.

Everything looks good to me, and I’m quite satisfied with the base names. I also hope the code aligns well with these updates.

Please do let me know if I’ve missed anything or if further adjustments are needed.

Thanks a lot!

Posted

@GLAVCVS 

Good day,

Please let me know if have any questions or issues in regards of lisp.

 

Thanks.

Posted

The basename 'electric' appears twice. I already told you
When the code finds a layer in the drawing that contains 'electric', the 'standard' list will return 2 options: 'E-ELECTRIC' and 'E-ELECTRIC STRUCTURE', which have different linetype scales.
There should only be 1 option for each 'BaseName'
So you'll need to delete 'E-ELECTRIC' or 'E-ELECTRIC STRUCTURE'. Or rename one of the two 'electric' 'basenames'.
Or both

Posted

Dear @GLAVCVS,

 

you're correct, The "electric" basename will have two options: "E-ELECTRIC" and "E-ELECTRIC STRUCTURE," both need to follow Std E-ELECTRIC layer property standards.

That what basename pattern matching features does like finding all results with similar names and apply same std to all.

 

If this is blocking progress, let's proceed without the electric layer and add it after the final LISP.

Posted

Let's proceed with an example:
if the code, during execution, finds a layer called 'ELECTRIC_CONDUCTION' in the drawing:
what 'Linetype Scale' should be assigned to it?

Posted

Dear @GLAVCVS,

 

Same as electric layer properties.

Screenshot_2025-02-03-23-02-54-175_cn_wps.moffice_eng-edit.thumb.jpg.2179965f9cd7b51fb77355b7043740d1.jpg

 

by the way i only knew lisp can set color, linetype, lineweight.

are we really changing LINETYPE SCALE thats great.

 

 

Posted (edited)

No
It is not possible to set the linetype scale per layer. Only by objects. 

Sorry for the confusion

Considering this, this is what your code could look like... 

 

(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 (edited)

Just a comment if you want to read Excel direct can open the correct Excel file. Just edit filename & sheetname

 

(setq myBook (vl-catch-all-apply 'vla-open (list (vlax-get-property myXL "WorkBooks") fileName)))
(setq mySheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property myBook "Sheets") "Item" sheetName)))
(vlax-invoke-method mySheet "Activate")

 

You can add say T5 & T6 values also to the standards list.

 

@GLAVCVS you mentioned no Excel do you use Libre Calc ? Have a get application for that its not as clean as Get Excel but it works. 

Edited by BIGAL
  • Like 1
Posted

Hi Bigal
Yes: I have LibreOffice on this PC.
I have never used it from AutoCAD.
What you say is interesting. I am curious to experiment with this.
Where can I find documentation?

Posted (edited)

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

Edited by BIGAL
  • Like 2
Posted
  19 hours ago, 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 · 0 downloads

Expand  

 

Thanks you very much

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