//used initially MECHANICALBLOCKSOPTIONS=0. The results differ if MECHANICALBLOCKSOPTIONS=1. [_AcTrx.CommandMethod("SR167025_getSetMechanicalProps_bmprops_mechMaterial")] public void SR167025_getSetMechanicalProps_bmprops_mechMaterial() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcEd.Editor ed = doc.Editor; ed.WriteMessage($"\n => Use: dw//167025_bminsert_myBox_mechanicalComponent.dwg";); _AcDb.ObjectId id = _AcDb.ObjectId.Null; _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("Select a Mechanical component insert"); peo.SetRejectMessage("Not a Block Reference!"); //peo.AddAllowedClass(typeof(_AcDb.BlockReference), true); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (_AcEd.PromptStatus.OK == per.Status) { _AcDb.Database db = _AcDb.HostApplicationServices.WorkingDatabase; _AcDb.TransactionManager dbTrManager = db.TransactionManager; using (_AcDb.Transaction tr = dbTrManager.StartTransaction()) { _AcDb.BlockReference blockRef = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; if (null != blockRef) { id = blockRef.ObjectId; //eug, based on: C:\Program Files\Bricsys\BricsCAD V23 en_US\API\dotNet\CsBrxMgd\CsBrxMgd\MechanicalComponents.cs _AcMec.ComponentInstance compInstance = _AcMec.ComponentInstance.GetComponentInstance(id); if (compInstance == null) { ed.WriteMessage("\n => Err: the selected block doesn't contain MechanicalComponents"); return; } _AcMec.ComponentDefinition compDef = _AcMec.ComponentDefinition.GetComponentDefinition(compInstance.InstanceBlockId, false); //string compName = compInstance.Name; //string compDefName = compDef.Name; //string compStatus = compDef.BomStatus.ToString(); //string compDescription = compDef.Description; //uint compType = (uint)compDef.ComponentType;//eug added cast ed.WriteMessage($"\nThe component insert name of the block reference with id={id} is {compInstance.Name} " + $"\ncomponentDefinitionName: {compDef.Name}"); //eug: SR //string materialName = compDef.Material;//temp ed.WriteMessage($"\n => compDef.Material='{compDef.Material}', is empty instead of 'Wood'");//! //* temp /* StringCollection parameterNames = _AcGc.Utility.GetBlockParameterNames(per.ObjectId);//eug: wrong call, needs a block REF id if (0 == parameterNames.Count) { ed.WriteMessage($"\n => parameterNames.Count=0. "); } foreach (String value in parameterNames) { ed.WriteMessage("\n => Parameter Name is {0}", value); } _AcGc.ConstraintsGroup3d[] allConstraintsGroups3d = _AcGc.Utility.GetAllConstraintsGroups3d(doc.Database); if (0 < allConstraintsGroups3d.Length) { ed.WriteMessage($"\n => allConstraintsGroups3d.Length={allConstraintsGroups3d.Length}. "); } */ _AcMec.ComponentDefinition compDef1 = _AcMec.ComponentDefinition.GetComponentDefinition(compDef.OriginalBlockId, false);//temp ed.WriteMessage($"\n => compDef1.Material='{compDef1.Material}', is empty instead of 'Wood'");//temp _AcMec.ComponentDefinition compDef2 = _AcMec.ComponentDefinition.GetComponentDefinition(per.ObjectId, false); ed.WriteMessage($"\n => compDef2.Material='{compDef2.Material}', is empty instead of 'Wood'");//ok for exploded component } //if the main block ref would be first exploded, to get body_1 _AcDb.Solid3d solid3d = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.Solid3d; if (null != solid3d) { id = solid3d.ObjectId; _AcMec.ComponentInstance compInstance = _AcMec.ComponentInstance.GetComponentInstance(id); if (compInstance == null) { ed.WriteMessage("\n => Err: the selected block doesn't contain MechanicalComponents"); return; } _AcMec.ComponentDefinition compDef = _AcMec.ComponentDefinition.GetComponentDefinition(compInstance.InstanceBlockId, false); ed.WriteMessage($"\nThe component insert name of the selected solid with id={id} is {compInstance.Name} " + $"\ncomponentDefinitionName: {compDef.Name}"); ed.WriteMessage($"\n => compDef.Material='{compDef.Material}', is empty instead of 'Wood'"); _AcMec.ComponentDefinition compDef1 = _AcMec.ComponentDefinition.GetComponentDefinition(compDef.OriginalBlockId, false);//temp ed.WriteMessage($"\n => compDef1.Material='{compDef1.Material}', is empty instead of 'Wood'");//temp _AcMec.ComponentDefinition compDef2 = _AcMec.ComponentDefinition.GetComponentDefinition(per.ObjectId, false); ed.WriteMessage($"\n => compDef2.Material='{compDef2.Material}', is empty instead of 'Wood'");//ok for exploded component } tr.Commit(); } } }