Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Export Clashes to txt file for import to excel speadsheet 1

Status
Not open for further replies.

CheeseMaker13

Aerospace
Sep 25, 2012
42
Hi,

I'd like to compile a macro that does the following things:

1. Imports a selection of assembly file names from an excel spreadsheet.
2. Runs clash detection on each of the files listed in the spreadsheet.
3A. Exports the clash list to a txt file for import into the same excel speadsheet OR
3B. Automatically imports the clashes straight into excel.

Now I can do steps 1 and 3A, but my very basic CATIA VBA knowledge is kinda putting me up against the buffers with Steps 2 and 3B.

I've done some googling to see if I could find any scripts similar to what I want to achieve, but they either don't work from the kick off or I can't make heads nor tails of them!

Could someone knock together a script that runs on an already opened assembly (starting from Set Target_Document = CATIA.Documents.Open(C:/....)) and explains what each step does would be awesome.

(Essentially, I'm ok with excel VBA, but I can't make heads nor tails of these catia objects and there doesn't seem to be any guides explaining what it all does on the internet, so anything that clarifies the basics of CATIA VBA [or object-based VBA itself] would be very useful!!!)

Thanks!
CR.
 
Replies continue below

Recommended for you

Also, I'd like the value of the clash to also be exported, as this is quite important!!
 
One of yours here: Also:
I put either into a catvba, run them and they error (can't pull up the error now as I'm away from a CATIA machine), I'm probably doing something dumb but still.

I'm guessing from reading through them that they contain the basis of what i need to achieve my goal?

Completely didn't know CATIA had automation documentation, is there somewhere online to access this as it is painfully slow at work!!!
 
Clashes are exported in a xml file, if you want to import them in Excel you need a macro to read this file and get what ever strings from there.

So, CATIA macro , then fire Excel macro :) (I think it can be done since it can be done in vbs).

CATIA Automation file on line...I believe Google can help you (as far as I know is not legal on other sites then DS), if not, search in your CATIA installation folder.

Regards
Fernando

 
Right, got back to a CATIA machine and I get the following error with this link's code:
Error: Compile Error, Expected user-define type, not project on line "Dim oClash as Clash" when run from a module in a catvba project.

Secondly, can this be changed to export to a txt file?

Many Thanks!!

James
 
Hi,

That macro was done for CATScript, not catvba, it was good for r12 or r14 if I remember corectly. Is very posible now to not work in recent versions due to the changes in automation language.

I don't have time now to check it but I will take a look soon. To export to a txt file.....no, I don't think so.

Regards
Fernando

 
Ah, I see!

I'm using R18.

If there isn't a way to export to text, is there any way of getting the results out (or doing my own clash routine)?

Although parsing the XML is probably just as easy as doing something else!!!

Thanks,
CR.
 
In my opinion, do (or modify) the clash routine (from the other link which you found or this one), save the results as xml file, then do another macro in Excel to read the xml file and extract from there what you need.

Open the xml file in a text editor , you can get more ideeas what you have to do in the Excel macro...you have to extract some rows...look at the xml file structure with a little attention :)

Regards
Fernando

 
Hi Fernando,

Thanks to your help in the other thread I'm now stuck here.

I've been using this: Macro to export my clashes.

However now I'm getting xmls that are far too large for excel to import.

Is there a way to limit the XML export to clashes only??

Thanks!
James
 
Managed to do something else instead, push the data straight to excel! I've also set it up so that it only loads the parts it needs into design mode, with it putting the whole lot back to visulisation mode if it runs out of memory:


My export code:

Code:
Private Sub ClashExport()
Dim cClashes As Clashes
'Dim oClash As Clashes
Dim dFilterValue As Double
Dim oConflict As Conflict
Dim Produs1 As Product
Dim oNume1 As String
Dim Produs2 As Product
Dim oNume2 As String
Dim prod1run As Long
Dim prod2run As Long
Dim InputRow As Integer

Set cClashes = CATIA_Product.Product.GetTechnologicalObject("Clashes")

dFilterValue = 0
InputRow = 2

Set oClash = cClashes.AddFromSel
oClash.ComputationType = catClashComputationTypeInsideOne
oClash.InterferenceType = catClashInterferenceTypeClearance
oClash.Compute

Set cConflicts = oClash.Conflicts

For i = 1 To cConflicts.Count

    Set oConflict = cConflicts.Item(i)
    
    If (oConflict.Type = catConflictTypeClash) Then
    
        Set Produs1 = oConflict.FirstProduct
        Produs1.ApplyWorkMode (DESIGN_MODE)
        oNume1 = Produs1.PartNumber
        If (UCase(Left(oNume1, 3)) = "RUN") Then
            prod1run = prod1run + 1
        End If
   
        Set Produs2 = oConflict.SecondProduct
        Produs2.ApplyWorkMode (DESIGN_MODE)
        oNume2 = Produs2.PartNumber
        If (UCase(Left(oNume2, 3)) = "RUN") Then
            prod2run = prod2run + 1
        End If
    
        If (oConflict.Value <> 0) Then
            oConflict.Status = catConflictStatusRelevant
            oConflict.Comment = "Automatic filter : penetration less than " & dFilterValue
            
            Excel_Sheet.Cells(InputRow, 1) = oConflict.FirstProduct.DescriptionRef & " (" & oConflict.FirstProduct.Name & ")"
            Excel_Sheet.Cells(InputRow, 2) = oConflict.SecondProduct.DescriptionRef & " (" & oConflict.SecondProduct.Name & ")"
            Excel_Sheet.Cells(InputRow, 3) = oConflict.Value
            
            Call Cell_Conditions(InputRow)
            
            InputRow = InputRow + 1
            
        End If


    ElseIf (oConflict.Type = catConflictTypeContact) Then
        oConflict.Status = catConflictStatusIrrelevant
    End If       
     
Next


My test code:

Code:
If GetMemUsage() / 1024 > 2200 Then
    CATIA_Product.Product.ApplyWorkMode (VISUALIZATION_MODE)
End If


Memory code:

Code:
Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Function GetMemUsage()
  
  ' Returns the current Excel.Application
  ' memory usage in MB
  
  Set objSWbemServices = GetObject("winmgmts:")
  GetMemUsage = objSWbemServices.Get("Win32_Process.Handle='" & GetCurrentProcessId & "'").WorkingSetSize / 1024
    
  Set objSWbemServices = Nothing
  
End Function





However, I have a new problem.


I now have:


Top Level Product
- Component 1
- Prod 1
- Prod 2
- Prod 3
- Component 2
- Prod 4
- Prod 5
- Prod 6


How can I use "catClashComputationTypeBetweenTwo" between components 1 and 2?

I've been trying to get them into groups but I've been failing miserably!!

Thanks
CR!

 
Hi,

You have a star for solution, is always good to see peoples doing progress, really.

In a CATScript ( again :) ).

Sub CATMain()

' get root product of document
Dim RootProd As Product
Set RootProd = CATIA.ActiveDocument.Product

' retrieve selection object of active document
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection

' get two selected objects
If (objSelection.Count2 <> 2) Then
MsgBox "Before running the script you must select two products to compute clash for", vbOKOnly, "No products selected"
Exit Sub
End If

Dim FirstProd As Product
Dim SecondProd As Product

Set FirstProd = objSelection.Item2(1).Value
Set SecondProd = objSelection.Item2(2).Value

' create groups for clash computation
Dim objGroups As Groups
Set objGroups = RootProd.GetTechnologicalObject("Groups")

Dim grpFirst As Group
Dim grpSecond As Group

Set grpFirst = objGroups.Add()
Set grpSecond = objGroups.Add()

' add selected products to groups
grpFirst.AddExplicit FirstProd
grpSecond.AddExplicit SecondProd


' get access to Clashes collection
Dim objClashes As Clashes
Set objClashes = RootProd.GetTechnologicalObject("Clashes")

' create new clash
Dim newClash As Clash
Set newClash = objClashes.Add()

' set new clash to be computed between two groups (two selected products)
newClash.FirstGroup = grpFirst
newClash.SecondGroup = grpSecond

newClash.ComputationType = catClashComputationTypeBetweenTwo

' compute clash
newClash.Compute

End Sub

Regards
Fernando

 
Is there any way of automatically selecting the two components as I know the names of them?

Component 1 = "MONKEYS"
Component 2 = "BANANAS"

Essentially my above script runs for about an hour, so will be left alone to get on with it. If the user needs to come back to select the two parts then that kinda defeats the point!

Thanks!
 
PS: Thanks very much for your help. Would have been stuck otherwise.
 
Hello, dear colleagues

@author:
Is there any way of automatically selecting the two components as I know the names of them?

Component_1 = "MONKEYS"
Component_2 = "BANANAS"


of course You can

I would do this in this way:

Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
product1 = productDocument1.GetItem(Component_1)
selection1.Add product1
not sure if it works with subassemblies

with regards
 
Right, thanks guys, all up and running for this project, anyway!!!

Code:

Code:
'Conflict Generatation Code
Private Sub ClashExport()

Dim cClashes As Clashes
Set cClashes = CATIA_Product.Product.GetTechnologicalObject("Clashes")


If STATEMENT Then
    Set oClash = cClashes.AddFromSel
    oClash.ComputationType = catClashComputationTypeInsideOne
    oClash.InterferenceType = catClashInterferenceTypeClearance
    oClash.Compute
End If


If *STATEMENT Then

    'Selects the two components for clash detection.
    Set selection1 = CATIA_Product.Selection
    Set product1 = CATIA_Product.Product.Products.Item(1)
    selection1.Add product1

    Set selection2 = CATIA_Product.Selection
    Set product2 = CATIA_Product.Product.Products.Item(2)
    selection2.Add product2


' create groups for clash computation
Dim objGroups As Groups
Set objGroups = CATIA_Product.Product.GetTechnologicalObject("Groups")

Dim grpFirst As Group
Dim grpSecond As Group

Set grpFirst = objGroups.Add()
Set grpSecond = objGroups.Add()

' add selected products to groups
grpFirst.AddExplicit product1
grpSecond.AddExplicit product2


' get access to Clashes collection
Dim objClashes As Clashes
Set objClashes = CATIA_Product.Product.GetTechnologicalObject("Clashes")

' create new clash
Set oClash = objClashes.Add()

' set new clash to be computed between two groups (two selected products)
oClash.FirstGroup = grpFirst
oClash.SecondGroup = grpSecond

oClash.ComputationType = catClashComputationTypeBetweenTwo

' compute clash
oClash.Compute
End If

Set cConflicts = oClash.Conflicts

'****Then export it...*****
 
Hi everyone,

I am new in the community. But when I saw this topic and that some of you seem to be experienced with the automation and exploitation of CATIA clashes analyses, I decided to register because I think may be one of you could help me and I think my issue is of interest for other CATIA users.

I am also developing a macro in order to export calshes into an excel or xml file.

I used a similar algo than yours but I have another issue to adress and to share with you.
I would like, for each of my identified contacts, to automatically publish the two surfaces of contacts in each of the parts in contact.

My idea is to use a point and identify and publish the closest surface from this point. I managed to code this macro but without any link with a conflicts detection.

This could work for interferences that I consider as relevant contacts (e.g. a threaded screw in a threaded hole) since I can get the first and second points coordinates.
It could also work with contacts identified throug the use of proximity/distance analyses but it is not feasible on large assemblies (too slow or it even often crashes before it ends)

My problem is to do it for my real contacts identified through the clah analysis tool. How can I get the both surfaces in contact? Other question : is any one knows how to automate the apparition of the preview window that could allow the user to decide himself what to do with the filtered interferences.

Thanks in advance

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor