Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

turn of underlayer in factory with ilogic

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Darkforce_the_ilogic_guy
542 Views, 7 Replies

turn of underlayer in factory with ilogic

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 

Tags (1)
7 REPLIES 7
Message 2 of 8

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

EESignature

(Not an Autodesk Employee)

Message 3 of 8

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

Tags (1)
Message 4 of 8

Hi @Darkforce_the_ilogic_guy 

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
Message 5 of 8
JhoelForshav
in reply to: JhoelForshav

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
Message 6 of 8

The DWG is an drawing generator by inventor form the Assets in 3d to an dwg by synz the Inventor iam to Autocad. I do not know how the program add it to Iam. Only that it always are call the same as the part number of the iam and add an extension. As an autocad file (.DWG). but the code to make an standard component change visibility does not seems to work
Message 7 of 8

@Darkforce_the_ilogic_guy 

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
Message 8 of 8

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

 

 

Tags (3)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report