Dim doc = ThisDoc.Document Dim sDocumentSubType As String = doc.SubType If sDocumentSubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" If Component.Visible(iProperties.Value("Project", "Part Number")&".dwg") =True Then Component.Visible(iProperties.Value("Project", "Part Number")&".dwg") = False Else Component.Visible(iProperties.Value("Project", "Part Number")&".dwg") = True End If Else End If
I want to make an code that turn the visbility on of off in an factory layout. Can anyone tell me what I need to change in my code? it have to work on all my IAM factory files. it is always call the same as the partnumber and ".dwg" in the browser tree. but the normale componemt code does not seens to work . It keep saying it can´t find it
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
I know that normally, in an assembly, the component names usually get something like ":1" automatically added to the ends of their names, by default. This can be a real pain when trying to specify Components by their Componene.Name.
I usually just loop through my components and check if oComp.Name.Contains("Name") = True, then process them.
I don't know if it would make much difference, but you could also try going one step deeper like this.
Component.InventorComponent("Part1").Visible =
Do you know if it is finding the component or not?
Another thing I do to avoid that long unreadable string for document subtype is access the documents iProperty for SubTypeName, like this.
MsgBox("The SubType of the Active Document = " & oDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value)
Wesley Crihfield
(Not an Autodesk Employee)
my problem is not there name... but that it seens that an Autocad link files does not count as an normale componemt.
there are not been add an :1 on this ... it is always call partnumber & ".dwg". but no matter if i type the number .. if saying it can´t find it
The dwg is an imported component.
Try this iLogic code 🙂
Dim oDoc As Document = ThisDoc.Document Dim sDocumentSubType As String = oDoc.SubType If sDocumentSubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim orefComp As ImportedComponent Dim orefCompName As String = iProperties.Value("Project", "Part Number") & ".dwg" orefComp = oDef.ImportedComponents.Item(orefCompName) If orefComp.Visible orefComp.Visible = False Else orefComp.Visible = True End If End If
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
On a side note; If the dwg is imported in a part document you'll find it under ComponentDefinition.ReferenceComponents.ImportedComponents. So in order to make the rule work in both part and assembly documents it'll have to look something like this:
Dim oDoc As Document = ThisDoc.Document Dim orefComp As ImportedComponent Dim orefCompName As String = iProperties.Value("Project", "Part Number") & ".dwg" If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Try orefComp = oDef.ImportedComponents.Item(orefCompName) Catch MessageBox.Show("No imported component with name: " & orefCompName & " exists in the document", _ "Cannot find component", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End Try ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition Try orefComp = oDef.ReferenceComponents.ImportedComponents.Item(orefCompName) Catch MessageBox.Show("No imported component with name: " & orefCompName & " exists in the document", _ "Cannot find component", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End Try End If If orefComp.Visible orefComp.Visible = False Else orefComp.Visible = True End If
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
I see... I don't have the factory design utilities myself, but I'm thinking it might be a ReferencedOLEFileDescriptor....
Try this rule and se if it gives you any messagebox:
Dim oDoc As AssemblyDocument = ThisDoc.Document Dim oleReference As ReferencedOLEFileDescriptor For Each oleReference In oDoc.ReferencedOLEFileDescriptors MsgBox(oleReference.DisplayName) Next
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
as it turn out that code did work . Thanks for the help. I add an marco that run that code. and made a buttom. so now I can do somthing in sekund that easy take minutes. the file that I test it on I did not even manage do it at all .. My computer frezz up it I try to use the normale inventor function with the mouse. but it toke less the 3 secund when I use our code/buttom
VBA code I use
Public Sub VisibleUnderlayer()
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
For Each addIn In addIns
If InStr(addIn.DisplayName, "iLogic") > 0 Then
addIn.Activate
Dim iLogicAuto As Object
Set iLogicAuto = addIn.Automation
Exit For
End If
Next
Debug.Print addIn.DisplayName
Dim RuleName1 As String
EXTERNALrule = "ChangeVisilibilityFactoryUnderlayer"
'Dim RuleName2 As String
'INTERNALrule = "Rule2"
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
'iLogicAuto.RunRule oDoc, INTERNALrule 'for internal rule
iLogicAuto.RunExternalRule oDoc, EXTERNALrule 'for external rule
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.