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: 

Multi Body Process

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
448 Views, 4 Replies

Multi Body Process

Am having trouble with the attached code related to the attached multibody part. What I am trying to do is run a process (veneering) on a part, which is one side of a piece of furniture. I have four parts, having made one part the only visible one, (hide others command), the code will detect that visible part and detect one of the largest faces to veneer. 

  The issue is, having cycled through the faces and found the largest face number, and stored that number, when that number is set as the face to veneer the process runs on a different (smaller ) face, despite the number being confirmed ( in a message box), as one of the largest faces. This happens only on parts 3 and 4 in the tree , but is ok on the other two.

I realise there are issues with face numbering, ie what starts off as say face 1, if the part is altered, the number of that face alters.   

  Hope some one can shed some light on this, as the part hasn’t been altered prior to the process happening.

Thanks in advance.

4 REPLIES 4
Message 2 of 5
frederic.vandenplas
in reply to: Anonymous

I would suggest to add attributes to your faces, because if you add faces, your query will indeed fail or result in unexpected behaviour.

 

After added attributes, you can easily query them!

 

http://modthemachine.typepad.com/my_weblog/attributes/

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 3 of 5
bshbsh
in reply to: Anonymous

Hi,

 

The biggest mistake is: you get n for the visible volume body:

For n = 1 To oCompDef.SurfaceBodies.Count

but then use the same n on extrudefeatures:

Set oFace1 = oCompDef.Features.ExtrudeFeatures.Item(n).Faces.Item(FaceNo)

they have nothing to do with each other. In fact, your "third" volume body is Volume4 (n=4), created by the extrusionfeature Extrusion3. So you look for the index of biggest face on the wrong volume. So you get the wrong FaceNoStore, which you later use for creating the sketch:

Set oFace2 = oCompDef.SurfaceBodies.Item(n).Faces.Item(FaceNoStore)

here you use the correct volume but the wrong faceno.

 

 

Public Sub FaceArea()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim num As Long
    Dim n As Long
    num = oCompDef.SurfaceBodies.Count
    For n = 1 To oCompDef.SurfaceBodies.Count
        If oCompDef.SurfaceBodies.Item(n).Visible = True Then
            
            MsgBox " Solid No   " & n & " of  " & num & " items. "
            
            Dim FaceNo As Long
            Dim AreaStore As Long
            Dim FaceNoStore As Long
            
            'FaceNo = 0 'useless, since the following For initializes it
            AreaStore = 0
            FaceNoStore = 0
            'For FaceNo = 1 To 6 'I got an error at 6 because one of the ExtrusionFeatures only got 5 Faces.
            For FaceNo = 1 To oCompDef.SurfaceBodies.Item(n).Faces.Count
                Dim oFace1 As Face
                Set oFace1 = oCompDef.SurfaceBodies.Item(n).Faces.Item(FaceNo)
                MsgBox "Face area of  " & FaceNo & "  " & oFace1.Evaluator.Area & " cm^2"
                If oFace1.Evaluator.Area > AreaStore Then
                    AreaStore = oFace1.Evaluator.Area
                    FaceNoStore = FaceNo   'Puts number of face in store -FaceNoStore
                End If
            Next FaceNo
            
            MsgBox " biggest face is number " & FaceNoStore & "  " & FaceNoStore
            MsgBox "n  = " & n
            MsgBox "Face number is    " & FaceNoStore
            
            Dim oFace2 As Face
            Set oFace2 = oCompDef.SurfaceBodies.Item(n).Faces.Item(FaceNoStore)
            
            MsgBox "Face number is    " & FaceNoStore
            Dim oSketch1 As PlanarSketch
            Set oSketch1 = oCompDef.Sketches.Add(oFace2, True)
            Dim oProfile As Profile
            Set oProfile = oSketch1.Profiles.AddForSolid
            Dim oExtrude As ExtrudeFeature
            Set oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, 0.2, kNegativeExtentDirection, kCutOperation)
            
            Dim oSideFace1 As Face
            Set oSideFace1 = oExtrude.EndFaces.Item(1)
            
            Dim oSketch3 As PlanarSketch
            Set oSketch3 = oDoc.ComponentDefinition.Sketches.Add(oSideFace1, True)
            Dim oProfile3 As Profile
            Set oProfile3 = oSketch3.Profiles.AddForSolid
            Set oExtrude = oDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile3, 0.2, kPositiveExtentDirection, kNewBodyOperation)
            
        End If
    Next
End Sub

There are a few more things to tidy up.

 

Message 4 of 5
Anonymous
in reply to: bshbsh

Hi  BshBsh.   Many Thanks for this. Yes it sorted the problem out.  I did build this up from various bits of code, samples and otherwise, and it appeared to work to a certain extent.  I did realise that the  part numbering was out of order, but didnt realise my debugging was giving ambiguous results.   Will persevere.  I was interested in the other reply to this post, and reading the link to Brian Ekins article in Mod the Machine.  Kind Regards 

Message 5 of 5
Anonymous
in reply to: frederic.vandenplas

Hi Frederick.. Thanks for your reply and the link to Brian Ekins article. At the outset it does seem like a positive way of referencing an item etc.  I think what I am trying to do relates to his mention of finding circular faces and sketching on them.   Kind Regards

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

Post to forums  

Autodesk Design & Make Report