Finding component face based on dimensions in assembly

Finding component face based on dimensions in assembly

Thomas.Long
Advocate Advocate
283 Views
0 Replies
Message 1 of 1

Finding component face based on dimensions in assembly

Thomas.Long
Advocate
Advocate

I'm attempting to create a section of code that will auto constrain a part that I input by cycling through the faces on the part to find the face.

I will be inputting the part type so it will know the dimensions of the part, but not the face name and not all of the face names will be the same as many of the parts are quite old and were made differently.

I only want to do this for one component at a time.

 

Right now, I have very little idea how to do this, so for now I'm just trying to get it to cycle through the faces and count them. Any and all help would be appreciated as this program will be very helpful but a little over my head. The intended goal long term is that this fits into another program that inputs parts one by one with the user specifying the part going in the and location (only one dimension will really be changing, they will be in a line) and the program will go through and orient and constrain the part correctly and then the user proceeds to do this for the next part until they specify they are finished.

 

SyntaxEditor Code Snippet

Sub Main()

FaceSearch("C15:1", 147.25, 2.600)

End Sub
    

Sub FaceSearch(Comp, Length, Width)

'Set Active Assembly
    Dim oAsmDoc As AssemblyDocument
    oAsmDoc = ThisApplication.ActiveDocument

'Assembly definition 
    Dim oAsmDef As AssemblyComponentDefinition
    oAsmDef = oAsmDoc.ComponentDefinition

    Dim docFile As Document
    
'Component & Component Face definition
    Dim oCompDef As Inventor.PartComponentDefinition
    oCompDef = docFile.ComponentDefinition

'Face Definition
    Dim oFace As Face

    i=0

       For Each Solid In oCompDef.Surfaces

        MessageBox.Show(i)
        i=i+1

    Next

End Sub

 

Right now I'm being passed the error "Object variable or With block variable not set," and I think its because I don't know how to specify in the For loop which part its supposed to be looking at. 

0 Likes
284 Views
0 Replies
Replies (0)