Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from shapely.geometry import LineString, Point
- import win32com.client
- import pythoncom
- from shapely.geometry.polygon import Polygon
- acad = win32com.client.Dispatch("AutoCAD.Application")
- acadModel = acad.ActiveDocument.ModelSpace
- doc_profile = acad.ActiveDocument
- def ADouble(xyz):
- return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (xyz))
- def variants(object):
- return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, (object))
- def APointWIN(x, y, z = 0):
- return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
- all_cycles = [
- [1048.1451395248105, 925.998569762405, 0.0, 1036.960636632246, 924.3, 0.0, 1022.2870059096047, 912.3, 0.0, 1011.6435029548023, 924.3, 0.0, 1022.2870059096047, 924.3, 0.0, 1036.960636632246, 932.3, 0.0, 1048.1451395248105, 937.998569762405, 0.0, 1057.8792670141918, 932.1787363587277, 0.0, 1048.1451395248105, 925.998569762405, 0.0],
- [1057.8792670141918, 928.1787363587277, 0.0, 1048.1451395248105, 913.998569762405, 0.0, 1036.960636632246, 924.3, 0.0, 1048.1451395248105, 925.998569762405, 0.0, 1057.8792670141918, 928.1787363587277, 0.0],
- [1057.8792670141918, 932.1787363587277, 0.0, 1048.1451395248105, 937.998569762405, 0.0, 1057.8792670141918, 944.1787363587277, 0.0, 1068.578652529347, 937.0834807441953, 0.0, 1057.8792670141918, 932.1787363587277, 0.0],
- ]
- layer_points = [
- [
- [1048.2451395248104, 926.398569762405, 'HEX', 'SQUARE', 'ANSI31'],
- [1048.2451395248104, 914.398569762405, 'STARS', 'STEEL'],
- ],
- [
- [1057.9792670141917, 932.5787363587277, 'TRIANG', 'SACNCR'],
- ]
- ]
- polygons = [Polygon(zip(cycle[::3], cycle[1::3])) for cycle in all_cycles]
- added_areas = set()
- for idx, points in enumerate(layer_points):
- for point in points:
- point_coords = point[:2]
- hatch_texts = point[2:]
- point_shapely = Point(*point_coords)
- for i, polygon in enumerate(polygons):
- if polygon.contains(point_shapely) and i not in added_areas:
- out_loop = [acadModel.AddPolyline(ADouble(all_cycles[i]))]
- # Hatches are created in this code block.
- for text in hatch_texts:
- hatch = acadModel.AddHatch(0, text, True)
- hatch.AppendOuterLoop(variants(out_loop))
- hatch.Evaluate()
- match text:
- case 'HEX' | 'SQUARE' | 'ANSI31' | 'STARS' | 'STEEL' | 'TRIANG' | 'SACNCR':
- hatch.PatternScale = 0.5
- case _:
- pass
- # Logically, this is where all the manipulation of exploding and forming the islands for the next hatch
- # .....................
- added_areas.add(i)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement