Create legend from hatches

Hi everyone,

I couldn’t find any post on this item so I figured there probably is no solution for this yet. Therefore I made a script myself to create a legend from all layers containing hatches, with hatch pattern from first hatch object on the layer. All layers without geometry are filtered out, all layers containing geometry other than hatches are cast into a seperate legend (by Civil3DToolkit Auto Legend).

Also in the script my interpretation of the AutoCAD layermanager search. I used regex to do this, is there any other method since the method I used is rather static (simple translation line by line).

Legend_hatches.dyn (117.0 KB)

Note: The script is made on C3D 2020

import re

layers = IN[0]
masks = IN[1].split(",")
regex = []

for mask in masks:
	m = mask
	m = m.replace("*", ".*")
	m = m.replace("-", "\-")
	m = m.replace("+", "\+")
	m = m.replace("_", "\_")
	m = m.replace("|", "\|")
	m = m.replace("?", ".")
	
	if not mask[0] == "*":
		m = "^" + m
	if not mask[-1] == "*":
		m = m + "$"

	regex.append(m)

res = []

for m in regex:
	res = []
	for lay in layers:
		if re.search(m, lay):
			res.append(lay)
	layers = None
	layers = res


OUT = res
3 Likes

Nice job @geert.drijfhout
(Good busy :smiley: )

I was looking for such a tool. Thanks a lot.