static void DisplayDependent(TransmittalFile tf, JsonOutput output) { int numberOfDependents = tf.numberOfDependents; for (int i = 0; i < numberOfDependents; ++i) { TransmittalFile childTF = tf.getDependent(i); FileType ft = childTF.FileType; var jsondependent = new Dependent(); jsondependent.Name = ft.ToString(); jsondependent.Path = childTF.sourcePath; output.Dependents.Add(jsondependent); DisplayDependent(childTF, output); } }
static public void QueryDwg() { //prompt for input json and output folder var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var res1 = ed.GetFileNameForOpen("Specify parameter file"); if (res1.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) { return; } /*var res2 = ed.GetString("Specify output sub-folder name"); * if (res2.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) * return;*/ try { //get parameter from input json var parameters = JsonConvert.DeserializeObject <Parameters>(File.ReadAllText(res1.StringResult)); //Directory.CreateDirectory(res2.StringResult); //extract layer names and block names from drawing as requested and place the results in the //output folder var db = doc.Database; //build XML output JsonOutput output = new JsonOutput { Blocks = new List <Block>(), Dependents = new List <Dependent>(), Layers = new List <Layer>() }; if (parameters.ExtractLayerNames) { using (var helper = new GeneralHelper()) { var list = helper.GetLayers().ToList(); if (list.Count > 0) { list.ForEach(layer => { var jsonlayer = new Layer(); jsonlayer.Name = layer.Name; jsonlayer.Description = layer.Description; output.Layers.Add(jsonlayer); }); } } } if (parameters.ExtractBlockNames) { using (var helper = new GeneralHelper()) { var list = helper.GetBlocks().ToList(); if (list.Count > 0) { list.ForEach(block => { var jsonblock = new Block(); jsonblock.Name = block.Name; jsonblock.Comments = block.Comments; jsonblock.Attributes = new List <AttributeDef>(); if (block.HasAttributeDefinitions) { //ed.WriteMessage("\n[INFO] Block name: " + block.Name); foreach (ObjectId id in block.GetBlockReferenceIds(true, false)) { if (!(id == ObjectId.Null)) { //ed.WriteMessage("\n[INFO] Block Ref Id: " + id); BlockReference blockRef = (BlockReference)id.GetObject(OpenMode.ForRead); AttributeCollection attCol = blockRef.AttributeCollection; if (attCol.Count > 0) { foreach (ObjectId attId in attCol) { if (!(attId == ObjectId.Null)) { AttributeReference attRef = (AttributeReference)attId.GetObject(OpenMode.ForRead); if (!(String.IsNullOrEmpty(attRef.Tag) && String.IsNullOrEmpty(attRef.TextString))) { //ed.WriteMessage("\n[INFO] Tag: " + attRef.Tag + " | Text: " + attRef.TextString); var jsonAttDef = new AttributeDef(); jsonAttDef.Tag = attRef.Tag; jsonAttDef.Text = attRef.TextString; jsonblock.Attributes.Add(jsonAttDef); } } } } } } } output.Blocks.Add(jsonblock); }); } } } if (parameters.ExtractDependents) { TransmittalFile tf; TransmittalOperation to = new TransmittalOperation(); TransmittalInfo ti = to.getTransmittalInfoInterface(); ti.includeDataLinkFile = 1; ti.includeDGNUnderlay = 1; ti.includeDWFUnderlay = 1; ti.includeFontFile = 1; ti.includeImageFile = 1; ti.includeInventorProjectFile = 1; ti.includeInventorReferences = 1; ti.includeMaterialTextureFile = 1; ti.includeNestedOverlayXrefDwg = 1; ti.includePDFUnderlay = 1; ti.includePhotometricWebFile = 1; ti.includePlotFile = 1; ti.includeUnloadedXrefDwg = 1; ti.includeXrefDwg = 1; if (to.addDrawingFile(doc.Name, out tf) == AddFileReturnVal.eFileAdded) { TransmittalFilesGraph tfg = to.getTransmittalGraphInterface(); TransmittalFile rootTF = tfg.getRoot(); DisplayDependent(rootTF, output); } } File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "results.json"), JsonConvert.SerializeObject(output)); } catch (System.Exception e) { ed.WriteMessage("Error: {0}", e); } }