Advertisement
bobbuban

Untitled

Apr 21st, 2024
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. from shapely.geometry import LineString, Point
  2. import win32com.client
  3. import pythoncom
  4. from shapely.geometry.polygon import Polygon
  5.  
  6.  
  7. acad = win32com.client.Dispatch("AutoCAD.Application")
  8. acadModel = acad.ActiveDocument.ModelSpace
  9. doc_profile = acad.ActiveDocument
  10.  
  11. def ADouble(xyz):
  12.     return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (xyz))
  13.  
  14. def variants(object):
  15.     return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_DISPATCH, (object))
  16.  
  17. def APointWIN(x, y, z = 0):
  18.     return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
  19.  
  20.  
  21. all_cycles = [
  22.     [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],
  23.     [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],
  24.     [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],
  25.  
  26. ]
  27.  
  28.  
  29. layer_points = [
  30.     [
  31.  
  32.         [1048.2451395248104, 926.398569762405, 'HEX', 'SQUARE', 'ANSI31'],
  33.         [1048.2451395248104, 914.398569762405, 'STARS', 'STEEL'],
  34.     ],
  35.     [
  36.  
  37.         [1057.9792670141917, 932.5787363587277, 'TRIANG', 'SACNCR'],
  38.     ]
  39. ]
  40.  
  41.  
  42. polygons = [Polygon(zip(cycle[::3], cycle[1::3])) for cycle in all_cycles]
  43. added_areas = set()
  44.  
  45. for idx, points in enumerate(layer_points):
  46.     for point in points:
  47.         point_coords = point[:2]
  48.         hatch_texts = point[2:]
  49.  
  50.         point_shapely = Point(*point_coords)
  51.         for i, polygon in enumerate(polygons):
  52.             if polygon.contains(point_shapely) and i not in added_areas:
  53.  
  54.                 out_loop = [acadModel.AddPolyline(ADouble(all_cycles[i]))]
  55.  
  56.  
  57.                 # Hatches are created in this code block.
  58.                 for text in hatch_texts:
  59.                     hatch = acadModel.AddHatch(0, text, True)
  60.                     hatch.AppendOuterLoop(variants(out_loop))
  61.                     hatch.Evaluate()
  62.  
  63.                     match text:
  64.                         case 'HEX' | 'SQUARE' | 'ANSI31' | 'STARS' | 'STEEL' | 'TRIANG' | 'SACNCR':
  65.                             hatch.PatternScale = 0.5
  66.                         case _:
  67.                             pass
  68.  
  69.  
  70.                 # Logically, this is where all the manipulation of exploding and forming the islands for the next hatch
  71.                 # .....................
  72.  
  73.                
  74.                 added_areas.add(i)
  75.                 break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement