/// ////////////////////////////////////////////////////////////////////////////////////////////////////// private static void DrawClientGraphicSolid(ref Inventor.Application _InvApplication, ref Inventor.ClientGraphics ClientGraphics, ref Inventor.AssemblyDocument assemblyDocument, string AssetName) {//"Clear - Green 1" "Clear" Inventor.Asset localAsset; localAsset = assemblyDocument.Assets[AssetName]; Inventor.GraphicsNode SurfacesNode = ClientGraphics.AddNode(1); SurfacesNode.Appearance = localAsset; Inventor.Box box = null; Inventor.SurfaceBody SurfaceBody; Inventor.TransientBRep TransientBRep; TransientBRep = _InvApplication.TransientBRep; Inventor.SurfaceGraphics SurfaceGraphics; int length = assemblyDocument.ComponentDefinition.Occurrences.Count; for (int i = length; i >= 1; i--) { if (GetInventorObjType(assemblyDocument.ComponentDefinition.Occurrences[i]) == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = assemblyDocument.ComponentDefinition.Occurrences[i]; box = componentOccurrence.RangeBox; SurfaceBody = TransientBRep.CreateSolidBlock(box.Copy()); SurfaceGraphics = SurfacesNode.AddSurfaceGraphics(SurfaceBody); SurfacesNode.Appearance = localAsset; } } _InvApplication.ActiveView.Update(); }
// ///////////////////////////////////////////////////////////////////////////////////////////////////// // Developing private void SetDocumentWorkPlanes(ref Inventor.ComponentOccurrence Occurrence, bool VisableState) { Inventor.Document Document = Occurrence.Definition.Document; if (Occurrence.DefinitionDocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject) { Inventor.PartDocument PartDocument = (Inventor.PartDocument)Document; foreach (Inventor.WorkPlane WP in PartDocument.ComponentDefinition.WorkPlanes) { if (WP.Visible != VisableState) { WP.Visible = VisableState; } } } else if (Occurrence.DefinitionDocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject) { Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document; foreach (Inventor.WorkPlane WP in AssemblyDocument.ComponentDefinition.WorkPlanes) { if (WP.Visible != VisableState) { WP.Visible = VisableState; } } } }
private static void GetDocumentDefinitionTypeByOccurrence(Inventor.ComponentOccurrence componentOccurrence) { switch (componentOccurrence.DefinitionDocumentType) { case Inventor.DocumentTypeEnum.kAssemblyDocumentObject: MessageBox.Show(componentOccurrence.DefinitionDocumentType.ToString()); break; case Inventor.DocumentTypeEnum.kPartDocumentObject: MessageBox.Show(componentOccurrence.DefinitionDocumentType.ToString()); break; case Inventor.DocumentTypeEnum.kDesignElementDocumentObject: MessageBox.Show(componentOccurrence.DefinitionDocumentType.ToString()); break; case Inventor.DocumentTypeEnum.kForeignModelDocumentObject: MessageBox.Show(componentOccurrence.DefinitionDocumentType.ToString()); break; case Inventor.DocumentTypeEnum.kUnknownDocumentObject: MessageBox.Show(componentOccurrence.DefinitionDocumentType.ToString()); break; default: break; } }
private Inventor.WorkPlane GetWorkPlaneOccurrance(ref Inventor.ComponentOccurrence ComponentOccurrence, string WorkPlaneAffix, string WorkPlaneSuffix) { Inventor.WorkPlane DefaultWorkPlane = null; if (WorkPlaneSuffix != "") { foreach (Inventor.WorkPlane WorkPlane in ComponentOccurrence.Definition.Document.WorkPlanes) { if (WorkPlane.Name == WorkPlaneAffix + " Plane") { return(WorkPlane); } } System.Windows.Forms.MessageBox.Show("Work Plane Not Fiound Affix: " + WorkPlaneAffix); return(DefaultWorkPlane); } else { foreach (Inventor.WorkPlane WorkPlane in ComponentOccurrence.Definition.Document.WorkPlanes) { if (WorkPlane.Name == WorkPlaneAffix + " " + WorkPlaneSuffix) { return(WorkPlane); } } System.Windows.Forms.MessageBox.Show("Work Plane Not Fiound: Affix " + WorkPlaneAffix + " Suffix " + WorkPlaneSuffix); return(DefaultWorkPlane); } }
private static void AddAttributeSets(Inventor.ComponentOccurrence componentOccurrence, String AttriSetsName, String AttriName, String AttriValue) { Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (!m_AttributeSets.NameIsUsed[AttriSetsName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(AttriSetsName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(AttriName, Inventor.ValueTypeEnum.kStringType, AttriValue); } }
public void RemoveGroup(ref Inventor.AssemblyDocument m_AssemblyDocument, String GroupName, String GroupNumber) { if (m_AssemblyDocument.SelectSet.Count == 0) { MessageBox.Show("Need to select a Part or Sub Assembly"); return; } Inventor.Assets colour = m_AssemblyDocument.Assets; foreach (var item in m_AssemblyDocument.SelectSet) { //Inventor.ComponentOccurrence occurrence = (Inventor.ComponentOccurrence)item; object objUnKnown = item; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; System.Diagnostics.Debug.WriteLine(objTypeEum.ToString()); if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)item; //(Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; System.Diagnostics.Debug.Print(componentOccurrence.Name + "Remove"); //Delete the attributes to the ComponentOccurrence if (m_AttributeSets.NameIsUsed[GroupName]) { m_AttributeSets[GroupName].Delete(); componentOccurrence.AppearanceSourceType = Inventor.AppearanceSourceTypeEnum.kPartAppearance; } } else if (objTypeEum == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject) { Inventor.RectangularOccurrencePattern RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)item; foreach (var Ritem in RectangularOccurrencePattern.OccurrencePatternElements) { Inventor.OccurrencePatternElement occurrencePatternElement = (Inventor.OccurrencePatternElement)Ritem; foreach (var Occitem in occurrencePatternElement.Occurrences) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)Occitem; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (m_AttributeSets.NameIsUsed[GroupName]) { m_AttributeSets[GroupName].Delete(); componentOccurrence.AppearanceSourceType = Inventor.AppearanceSourceTypeEnum.kPartAppearance; System.Diagnostics.Debug.Print(componentOccurrence.Name + "Remove Att and color"); } } } } } }
//switch (GetInventorObjType(JustSelected[i])) //{ // case Inventor.ObjectTypeEnum.kComponentOccurrenceObject: // //Inventor.ComponentOccurrence ComponentOccurrence = (Inventor.ComponentOccurrence)objUnKnown; // //ColourIt(AssemblyDocument, ComponentOccurrence); // //System.Diagnostics.Debug.WriteLine(ComponentOccurrence.Name); // return objTypeEum; // break; // case Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject: // //Inventor.RectangularOccurrencePattern RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)objUnKnown; // //foreach (var Ritem in RectangularOccurrencePattern.OccurrencePatternElements) // //{ // // Inventor.OccurrencePatternElement occurrencePatternElement = (Inventor.OccurrencePatternElement)Ritem; // // foreach (var Occitem in occurrencePatternElement.Occurrences) // // { // // Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)Occitem; // // ColourIt(AssemblyDocument, componentOccurrence); // // } // //} // break; // default: // break; //} //foreach (object item in JustSelectedEntities) //{ // ObjType(item); // System.Diagnostics.Debug.WriteLine("Just Selected"); //} //if (MoreSelectedEntities != null) //{ // foreach (object item in MoreSelectedEntities) // { // ObjType(item); // System.Diagnostics.Debug.WriteLine("More Selected"); // } //} //Inventor.AssemblyDocument AssemblyDocument, //string Colour = "Red"; //ColourOccurance(AssemblyDocument, componentOccurrence, Colour); //,Inventor.AssemblyDocument AssemblyDocument private static void AddAttributeSets(ref Inventor.ComponentOccurrence componentOccurrence, string AttributeSets_Name, string Attribute_Name, string Attribute_Value) { if (AttributeSets_Name != null || Attribute_Name != null) { Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (!m_AttributeSets.NameIsUsed[AttributeSets_Name]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(AttributeSets_Name); Inventor.Attribute m_Attribute = m_AttributeSet.Add(Attribute_Name, Inventor.ValueTypeEnum.kStringType, Attribute_Value); } } }
public void AddForAttributes(Inventor.AssemblyDocument m_AssemblyDocument, Inventor.SelectSet selectSet, string GroupName, int cnt) { // int cnt = m_AssemblyDocument.SelectSet.Count; // Inventor.SelectSet selectSet = m_AssemblyDocument.SelectSet; // m_AssemblyDocument.SelectSet.GetEnumerator().Current.GetType(); for (int i = cnt; i >= 1; i--) { // object itm = selectSet[i]; try { object objUnKnown = selectSet[i]; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (!(m_AttributeSets is null)) { // Add the attributes to the ComponentOccurrence Name = "GroupObject"; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } } } catch (Exception) { MessageBox.Show("Exception"); } } }
public static void DrawRangeBoxs(ref Inventor.Application Inv_Application, ref Inventor.AssemblyDocument assemblyDocument, Inventor.ObjectsEnumerator justSelectedEntities) { //Inventor.ComponentDefinition componentDefinition = (Inventor.ComponentDefinition)assemblyDocument.ComponentDefinition; if (justSelectedEntities.Count >= 1) { if (assemblyDocument.GraphicsDataSetsCollection.Count >= 1) { int length = justSelectedEntities.Count; for (int i = length - 1; i >= 0; i--) { if (GetInventorObjType(justSelectedEntities[i]) == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.Box box = null; System.Diagnostics.Debug.WriteLine("Just Selected"); Inventor.ComponentOccurrence componentOccurrence = justSelectedEntities[i]; box = componentOccurrence.RangeBox; } //else if (GetInventorObjType(justSelectedEntities[i]) == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject) //{ // Inventor.OccurrencePattern OccurrencePattern = justSelectedEntities[i]; // int PatternLength = 10; // for (int x = PatternLength - 1; x >= 1; x--) // { // } //} use after idea tested } } else { Inventor.ClientGraphics clientGraphics = assemblyDocument.ComponentDefinition.ClientGraphicsCollection["RangeID"]; assemblyDocument.GraphicsDataSetsCollection["RangeID"].Delete(); clientGraphics.Delete(); } } else { return; } }
public void HideOrShowGroup(ref Inventor.AssemblyDocument m_AssemblyDocument, bool hide, String GroupName, String GroupNumber) { try { Inventor.AttributeManager attbMan = m_AssemblyDocument.AttributeManager; Inventor.ObjectCollection objCol = default(Inventor.ObjectCollection); objCol = attbMan.FindObjects(GroupName, GroupName + "A", "G"); Inventor.ComponentOccurrence componentoccurrence = default(Inventor.ComponentOccurrence); int length = objCol.Count; for (int i = 1; i <= length; i++) { componentoccurrence = (Inventor.ComponentOccurrence)objCol[i]; componentoccurrence.Visible = hide; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Problem hiding component"); } }
private static void AddForAttributes(ref Inventor.AssemblyDocument m_AssemblyDocument, Inventor.SelectSet selectSet, string GroupName, int cnt) { // int cnt = m_AssemblyDocument.SelectSet.Count; // Inventor.SelectSet selectSet = m_AssemblyDocument.SelectSet; // m_AssemblyDocument.SelectSet.GetEnumerator().Current.GetType(); for (int i = 1; i <= cnt; i++) { // object itm = selectSet[i]; object objUnKnown = selectSet[i]; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; // System.Diagnostics.Debug.Print(componentOccurrence.Name); // System.Diagnostics.Debug.Print("Counter: " + i.ToString()); if (!(m_AttributeSets is null)) { // Add the attributes to the ComponentOccurrence Name = "GroupObject"; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } } } }
private static void AddAttributes(ref Inventor.ObjectsEnumerator JustSelected, ref Inventor.AssemblyDocument assemblyDocument) { int length = JustSelected.Count; for (int i = length - 1; i >= 1; i--) { if (GetInventorObjType(JustSelected[i]) == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { System.Diagnostics.Debug.WriteLine("Just Selected"); Inventor.ComponentOccurrence componentOccurrence = JustSelected[i]; ColourOccurance(ref assemblyDocument, ref componentOccurrence, "Red"); } else if (GetInventorObjType(JustSelected[i]) == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject) { Inventor.OccurrencePattern OccurrencePattern = JustSelected[i]; int PatternLength = 10; //OccurrencePattern.OccurrencePatternElements. for (int x = PatternLength - 1; x >= 1; x--) { } } } }
public static void TestDrawRangeBoxs(ref Inventor.Application _InvApplication, ref Inventor.AssemblyDocument assemblyDocument, ref Inventor.ComponentOccurrences Occurrences, string GraphicsName) { if (Occurrences.Count >= 1) { Inventor.ClientGraphics ClientGraphics = null; Inventor.GraphicsCoordinateSet CoordSet = null; Inventor.GraphicsDataSets GraphDataSets = null; Inventor.Box box = null; DeleteNamedGraphics(ref assemblyDocument, GraphicsName); CoordSet = SetClientGraphics(ref assemblyDocument, ref ClientGraphics, ref GraphDataSets, GraphicsName); int length = Occurrences.Count; for (int i = length; i >= 1; i--) { if (GetInventorObjType(Occurrences[i]) == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { System.Diagnostics.Debug.WriteLine("Just Selected"); Inventor.ComponentOccurrence componentOccurrence = Occurrences[i]; box = componentOccurrence.RangeBox; DrawBox(ref _InvApplication, ref ClientGraphics, ref CoordSet, ref GraphDataSets, ref box); } //else if (GetInventorObjType(justSelectedEntities[i]) == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject) //{ // Inventor.OccurrencePattern OccurrencePattern = justSelectedEntities[i]; // int PatternLength = 10; // for (int x = PatternLength - 1; x >= 1; x--) // { // } //} use after idea tested } } else { return; } }
private static void SetHighLightSet(ref Inventor.Application _InvApplication, ref Inventor.AssemblyDocument assemblyDocument, ref Inventor.ComponentOccurrences Occurrences, string GraphicsName) { if (Occurrences.Count >= 1) { //Inventor.ObjectCollection objectCollection = _InvApplication. Inventor.HighlightSet highlightSet = assemblyDocument.HighlightSets.Add(); highlightSet.Color = _InvApplication.TransientObjects.CreateColor(255, 0, 0, 1); //highlightSet.AddMultipleItems(Occurrences); int length = Occurrences.Count; for (int i = length; i >= 1; i--) { if (GetInventorObjType(Occurrences[i]) == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { System.Diagnostics.Debug.WriteLine("Just Selected"); Inventor.ComponentOccurrence componentOccurrence = Occurrences[i]; //highlightSet.AddItem(componentOccurrence); } } } else { return; } }
private static void ColourOccurance(Inventor.AssemblyDocument AssemblyDocument, Inventor.ComponentOccurrence componentOccurrence, string Colour) { Inventor.Asset asset = AssemblyDocument.Assets[Colour]; //this to sort out componentOccurrence.Appearance = asset; }
private static void AddEachAttributes(ref Inventor.AssemblyDocument m_AssemblyDocument, bool SelectAllArrays, String GroupName, String GroupNumber) { if (m_AssemblyDocument.SelectSet.Count == 0) { MessageBox.Show("Need to select a Part or Sub Assembly"); return; } Inventor.Assets colour = m_AssemblyDocument.Assets; try { foreach (var item in m_AssemblyDocument.SelectSet) { object objUnKnown = item; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; System.Diagnostics.Debug.WriteLine(objTypeEum.ToString()); if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)item;//(Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; System.Diagnostics.Debug.Print(componentOccurrence.Name); // Add the attributes to the ComponentOccurrence Name = "GroupObject"; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } else if (objTypeEum == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject && SelectAllArrays) { Inventor.RectangularOccurrencePattern RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)item; foreach (var Ritem in RectangularOccurrencePattern.OccurrencePatternElements) { Inventor.OccurrencePatternElement occurrencePatternElement = (Inventor.OccurrencePatternElement)Ritem; foreach (var Occitem in occurrencePatternElement.Occurrences) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)Occitem; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } } } } } catch (Exception ex) { MessageBox.Show("Is the selected item a Component?"); MessageBox.Show(ex.ToString()); return; } }
private void CreateAssemblyiMateConstraint(ref Inventor.AssemblyComponentDefinition AssemblyComponentDefinition, ref Inventor.ComponentOccurrence BaseComponentOccurrence, Inventor.ComponentOccurrence PositionComponentOccurrence, string BaseMateName, string PositionMateName, string affix) { bool BaseMateFound = false; bool PositionMateFound = false; Inventor.iMateDefinition BaseMateDefinition = null; Inventor.iMateDefinition PositionMateDefinition = null; Inventor.iMateResult iMateResult = null; foreach (Inventor.iMateDefinition MateDefinition in BaseComponentOccurrence.iMateDefinitions) { if (MateDefinition.Name == BaseMateName + ":" + affix) { BaseMateDefinition = MateDefinition; BaseMateFound = true; } } foreach (Inventor.iMateDefinition MateDefinition in PositionComponentOccurrence.iMateDefinitions) { if (MateDefinition.Name == BaseMateName + ":" + affix) { PositionMateDefinition = MateDefinition; PositionMateFound = true; } } if (BaseMateFound && PositionMateFound) { iMateResult = AssemblyComponentDefinition.iMateResults.AddByTwoiMates(BaseMateDefinition, PositionMateDefinition); } }
private void CreateConstraints(ref Inventor.AssemblyDocument AssemblyDocument, ref Inventor.ComponentOccurrence BaseComponentOccurrence, Inventor.ComponentOccurrence PositionComponentOccurrence, string BaseWorkPlaneName, string PositionMateWorkPlaneName, string Affix, string Seperator, string Suffix) { Inventor.WorkPlane BaseWorkPlane = null; Inventor.WorkPlane PositionWorkPlane = null; BaseWorkPlane = GetAssemblyDocumentWorkPlane(ref AssemblyDocument, "", ""); PositionWorkPlane = GetAssemblyDocumentWorkPlane(ref AssemblyDocument, "", ""); if (BaseWorkPlane.Type == Inventor.ObjectTypeEnum.kWorkPlaneObject && PositionWorkPlane.Type == Inventor.ObjectTypeEnum.kWorkPlaneObject) { } }