Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MACRO: exporting images after clash analysis

Status
Not open for further replies.

lgms

New member
Sep 24, 2018
3
Hi Everyone!
I am trying to do multiple clash reports and create only one excel report. I have done almost everything, but I could not create the images of each clash (just like the xml file does when you export it) to my excel report.

Is there a function that automatic get an image like the clash preview or should I make a routine for the user to photograph the conflict the way they want it?
can anyone help me with that?

the part of the code where I run the clash and get the results is below
Code:
        Dim oFirstMechanism 'As Mechanism
        oFirstMechanism = cTheMechanisms.Item(1)

        Dim parameters2 As Parameters
        parameters2 = product1.Parameters

        Dim joints1 As Joints
        joints1 = oFirstMechanism.Joints

        Dim GearJoint As Joint
        GearJoint = joints1.Item(4)

        dValcmd(0) = 0
        Dim i = 0

        '3-Retrieve current command values
        '*********************************
        oFirstMechanism.GetCommandValues(dValcmd)
        oFirstMechanism.Update()

        Dim maxStep As Integer
        Dim nStep As Integer

        'configure nstep and maxstep
        '*********************************************
        Try
            maxStep = TxtBoxMaxStep.Text
            nStep = TxtBoxStep.Text
        Catch ex As Exception
            CloseExcel()
            Return -1
        End Try

        Dim k As Integer = 1
        For i = 0 To maxStep Step nStep
     
            ' 4.a-Create another command set
            '*******************************
            dValcmd(0) = i

            ' 4.b-Apply the command set
            '**************************
            oFirstMechanism.PutCommandValues(dValcmd)

            If i = 0 Then oFirstMechanism.Update()

            'Run Clash and get the Conflicts results
            '*******************************************
            oClash.Compute()
            cConflicts = oClash.Conflicts

            'Take clash conflicts values and export to excel
            '*********************************************
            xlApp.Visible = True
            For j As Integer = 1 To cConflicts.Count
                oConflict = cConflicts.Item(j)
                If oConflict.Value < 0 Then

                    xlWorkSheet.Cells(k + 1, 1).Value = i
                    xlWorkSheet.Cells(k + 1, 2).Value = j
                    xlWorkSheet.Cells(k + 1, 3).Value = oConflict.FirstProduct.Name
                    xlWorkSheet.Cells(k + 1, 4).Value = oConflict.SecondProduct.Name
                    xlWorkSheet.Cells(k + 1, 5).Value = oConflict.Value
                    xlWorkSheet.Cells(k + 1, 6).Value = oConflict.Type
                    xlWorkSheet.Cells(k + 1, 7).Value = oConflict.Status
                    xlWorkSheet.Cells(k + 1, 8).Value = oConflict.Comment

                    k = k + 1
                End If
            Next
        Next
 
 https://files.engineering.com/getfile.aspx?folder=0d2b613e-d7bd-4a75-962e-c972c434163e&file=CLASH_IMG.png
Replies continue below

Recommended for you

hi, can you just make that xml first, and take all pictures from folder of xml?? Xml do the same, here is from xml file FirstProductURL = "Picture/24_9_2018_22_48_4_Preview_First_1.png" SecondProductURL = "Picture/24_9_2018_22_48_4_Preview_Second_1.png"/. It takes picture from that folder and combine them. I hope this can help.

To get that u can run 1 loop and split with that "Preview_First_" ( 24_9_2018_22_48_4_Preview_First_1) and second loop with "Preview_Second_".
In the end you can always delete this files.



Sub Export( CatClashExportType iType, CATBSTR iPath)

Exports the results in a XML file.
Parameters:
iType
The type of export.
iPath
The path of the file.
Example:
This example exports the results of NewClash Clash.
Dim ThePath As String
NewClash.Export CatClashExportTypeXMLResultOnly, "c:\tmp\sample.xml
 
Hi, Harun, I tried to use the xml but the it takes to much time to generate only one xml and I would need to generate like, 30 or even 100 xml depending on the kinematics of the product.
The image show the time to run: 2 clashes generating xml and the 2 clashes just exporting the values to excel
time_delay_rnfgec.png


I will try to generate it in another thread to help, but I don't know if the delay in generating the xml would be acceptable to the user.


Thanks for your reply!
 
Yeah i can understand that, but i think it also need a lot of time when doing it manually. Beacuse CATIA need some time to export it, did you try to measrue time when u make it manually?
Is there any possibility to run those in same time?

 
After talking with some co-workers, I ended up doing the routine for the user to take the picture. It is better for the user to choose the view and only take pictures of the parts they want.

Code:
Private Sub TakePicture(ByVal row As Integer)

        UtilityLibrary.CATIA.ActivateCATIA()

        Using form = New Form() With {.TopMost = True}
            MessageBox.Show(form, "Position the parts before taking the picture", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Using

        Dim MyWindow As SpecsAndGeomWindow
        Dim MyViewer As Viewer3D
        Dim CapturePath As String
        Dim BGWhite(2)
        BGWhite = {1, 1, 1}
        Dim BGcolor(2)

        MyWindow = CATIA.ActiveWindow

        MyViewer = MyWindow.ActiveViewer

        SaveFileDialog1.FileName = "StepNumber" & DataGridView1.Rows(row).Cells(0).Value & "_Clash" & DataGridView1.Rows(row).Cells(1).Value
        SaveFileDialog1.Filter = "BitMap Image|*.bmp"
        SaveFileDialog1.ShowDialog()
        CapturePath = IO.Path.GetFullPath(SaveFileDialog1.FileName)


        If CapturePath <> "" Then
            MyWindow.Layout = CatSpecsAndGeomWindowLayout.catWindowGeomOnly

            MyViewer.GetBackgroundColor(BGcolor)   ' Keep Background color in the array

            MyViewer.PutBackgroundColor(BGWhite) ' Change background color to WHITE
            MyViewer.CaptureToFile(CatCaptureFormat.catCaptureFormatBMP, CapturePath) 
            MyViewer.PutBackgroundColor(BGcolor) ' Change background color to the original color 

            MyWindow.Layout = CatSpecsAndGeomWindowLayout.catWindowSpecsAndGeom
            DataGridView1.Rows(row).Cells(7).Value = CapturePath

        End If

    End Sub

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor