How to mate pipe to many holes in sheet with api?

How to mate pipe to many holes in sheet with api?

mucip
Collaborator Collaborator
667 Views
8 Replies
Message 1 of 9

How to mate pipe to many holes in sheet with api?

mucip
Collaborator
Collaborator

Hi,

I need your valuable advice please.

I have many holes but not really hole infact. Many circles and cut on the sheet.

I have pipe with I mate on it's circle. I need to put/mate pipes with all circle cuts (not really hole).

I have seen how to get circle cut quantity on sheet here .

How can I mate pipes on each circle on sheet part with VB?

 

Regards,

Mucip:)

0 Likes
Accepted solutions (1)
668 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

You could do something like this. You run this rule from an assembly that contains the part with all the holes. the rule will ask you to select the part with the holes. The part will open and you need to select the face with all the holes. Then it will create iMates on all holes (that are not holes ;-). Lastly the rule will add the pipe with imates.

You will need to change the "Pipe" file name in the rule.

Dim doc As AssemblyDocument = ThisDoc.document

Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select chees part.")


Dim refDoc As PartDocument = occ.ReferencedDocumentDescriptor.ReferencedDocument
refDoc = ThisApplication.Documents.Open(refDoc.FullDocumentName)

Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select face with holes")

For Each edge As Edge In face.Edges
    If edge.GeometryType <> CurveTypeEnum.kCircleCurve Then Continue For

    refDoc.ComponentDefinition.iMateDefinitions.AddInsertiMateDefinition(edge, True, 0)
Next

doc.Activate()

doc.ComponentDefinition.Occurrences.AddUsingiMates("C:\Path\to\your\pipe.ipt", True)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 9

mucip
Collaborator
Collaborator

Hi,

Great idea. Thanks... 🙂

But I need to know the size of cheese holes. I need to put pipe on holes which is 50mm diameter only?

How can I get the diameter of circleEdge?

 

I attached picture of my part.

 

Regards,

Mucip:)

0 Likes
Message 4 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

I could not test this now but you can give it a go. Change the variable 'placeOnHoleWithRadius' to your needs.

'<-- 'placeOnHoleWithRadius' needs to be in centimeters
'More info on: http://hjalte.nl/46-parameter-document-database-units
Dim placeOnHoleWithRadius = 1.5 '= 15mm

Dim doc As AssemblyDocument = ThisDoc.Document

Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select chees part.")


Dim refDoc As PartDocument = occ.ReferencedDocumentDescriptor.ReferencedDocument
refDoc = ThisApplication.Documents.Open(refDoc.FullDocumentName)

Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select face with holes")

For Each edge As Edge In face.Edges
    If edge.GeometryType <> CurveTypeEnum.kCircleCurve Then Continue For
    Dim holeRadius = edge.Geometry.Radius
    If (holeRadius <> placeOnHoleWithRadius) Then Continue For

    refDoc.ComponentDefinition.iMateDefinitions.AddInsertiMateDefinition(edge, True, 0)
Next

doc.Activate()

doc.ComponentDefinition.Occurrences.AddUsingiMates("C:\Path\to\your\pipe.ipt", True)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 9

mucip
Collaborator
Collaborator

Hi,

Perfect. Thanks. I will try and inform you.But the problem is: When you run the code it crates imates everytime on cheese holes. I guess we need to clear all imates first to prevent duplicate imates.

I am searching this now. I need to iterate all imates and delete them first.

 

Regards,

Mucip:)

0 Likes
Message 6 of 9

mucip
Collaborator
Collaborator

Hi,

Creating imates according to size is working perfect.

But adding parts with imate is getting attached error.

 

Regards,

Mucip:)

0 Likes
Message 7 of 9

JelteDeJong
Mentor
Mentor

Can you try to add the pipe to the chees manually using the generated iMates? Does that work or do you get an error that is a bit more useful?

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 8 of 9

mucip
Collaborator
Collaborator

Hi,

OK. I will try and inform you?

By the way at teh begining we need to delete older imates. Any code sample please?

 

Regards,

Mucip:)

0 Likes
Message 9 of 9

mucip
Collaborator
Collaborator

Hi,

Eveything is OK now. I can delete all imates and re-assign imates on each holes again.

I can add rod on the asembly but can not mate rod and cheese part. I use below code:

 'imate adedi kadar mil çağrılıp mate edilecek.
        Dim oMatrix As Matrix
        oMatrix = inv_App.TransientGeometry.CreateMatrix
        Dim oOcc1 As ComponentOccurrence
        Dim oiMateResult As iMateResult

        Dim oAsmCompDef As AssemblyComponentDefinition
        oAsmCompDef = doc.ComponentDefinition

        For sayac = 1 To imateAdet

            oOcc1 = oAsmCompDef.Occurrences.Add("C:\Users\HP\Documents\Inventor\genel\mil.ipt", oMatrix)

            Dim oiMateDef1 As iMateDefinition = oOcc1.iMateDefinitions.Item(1)
            Dim oiMateDef2 As iMateDefinition = oCompdef.iMateDefinitions.Item(sayac)


            Try
                'Console.WriteLine("Mil " & oOcc1.iMateDefinitions.Item(1).Name)
                'Console.WriteLine("Sac " & oCompdef.iMateDefinitions.Item(sayac).Name)
                'oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)

                oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef2, oiMateDef1)

            Catch ex As Exception
                MsgBox(ex.Message)

            End Try
        Next
0 Likes