So… it’s been one of those days…
All I want is to grab the hatch in a dwg, grab it’s outline and extrude them.
Seems simple…?! Hmmm…
I can get the hatches, but they are not associated so the GetLoopAt method for comObjects fails.
So I need to stay within AutoCAD and use something like “-HatchEdit” or “HATCHGENERATEBOUNDARY” unfortunately this means using LISP (woop another coding language) and they all get dumped on the active layer, so I don’t know whether it’s to be extruded the height of a building or the height of a kerb.
This would be fine if I had the same number of objects as boundaries, unfortunately that doesn’t happen… So I need to iterate through each object, grab it’s layer and get any boundaries and dump that in it’s own list.
Unfortunately I haven’t been able to loop inside AutoCAD, I can only get all the hatches and extract all of them with PickfirstSelectionSet. I need to pick each hatch in turn, but I can’t think of a workflow for that
Any assistance greatly appreciated!
CAD Hatch dwg outlines.dyn (16.0 KB)
#LinkDWG Core DYF by Koz Jono YEOH #email@example.com #Copyright(C) 1994-2018 KozMos Inc. #Copyright(C) 2011-2018 Neila Heaven Networks #Cioyright(c) 2017-2018 Tachyon Intelligent Design Institute import clr clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager def _GetOrCreateAutoCAD(progid): try: from System.Runtime.InteropServices import Marshal return Marshal.GetActiveObject(progid) except: try: from System import Type, Activator t = Type.GetTypeFromProgID(progid) return Activator.CreateInstance(t) except: pass def _ValidFile(filename): try: with open(filename) as f: return True except IOError: return False UIDOC = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument DWG = UnwrapElement(IN) VIS = IN RTN = [None] if DWG != None: try: LNK=UIDOC.Document.GetElement(DWG.GetTypeId()) PATH=ModelPathUtils.ConvertModelPathToUserVisiblePath(LNK.GetExternalFileReference().GetAbsolutePath()) if _ValidFile(PATH): try: CAD=_GetOrCreateAutoCAD("Autocad.Application") CAD.Visible=VIS DOC=CAD.Documents.Open(PATH) DOC.SendCommand("(SSGET\"_x\"'((-4 . \"<OR\")(0 . \"*TEXT,*HATCH\")(-4 . \"<AND\")(0 . \"INSERT\")(66 . 1)(-4 . \"AND>\")(-4 . \"OR>\"))) ") DOC.SendCommand("SELECT (SSGET\"_p\") ") DOC.SendCommand("HATCHGENERATEBOUNDARY ") SEL=DOC.PickfirstSelectionSet RRR= for obj in SEL: if obj.ObjectName == "AcDbHatch": RRR.append([obj, obj.Layer]) RTN=RRR #doc except: pass except: pass OUT = RTN