Export Clashes to txt file for import to excel speadsheet
Export Clashes to txt file for import to excel speadsheet
(OP)
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.
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.





RE: Export Clashes to txt file for import to excel speadsheet
RE: Export Clashes to txt file for import to excel speadsheet
Did you check FAQ and search this forum about clash ?
If I remember, there are few clash threads here.
Can you upload (or indicate) where are those macros which are not working and what is not working ?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
Also: http://www.eng-tips.com/viewthread.cfm?qid=308161
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!!!
RE: Export Clashes to txt file for import to excel speadsheet
So, CATIA macro , then fire Excel macro
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
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
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
RE: Export Clashes to txt file for import to excel speadsheet
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
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
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.
RE: Export Clashes to txt file for import to excel speadsheet
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
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
Thanks to your help in the other thread I'm now stuck here.
I've been using this: http://www.eng-tips.com/viewthread.cfm?qid=308161 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
RE: Export Clashes to txt file for import to excel speadsheet
I know Excel is limited, thats why I was written "do another macro in Excel to read the xml file and extract from there what you need".
Read doesn't mean necessary to open in Excel...
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
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 NextMy test code:
CODE
If GetMemUsage() / 1024 > 2200 Then CATIA_Product.Product.ApplyWorkMode (VISUALIZATION_MODE) End IfMemory 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 FunctionHowever, 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!
RE: Export Clashes to txt file for import to excel speadsheet
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
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
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!
RE: Export Clashes to txt file for import to excel speadsheet
RE: Export Clashes to txt file for import to excel speadsheet
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Export Clashes to txt file for import to excel speadsheet
@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
RE: Export Clashes to txt file for import to excel speadsheet
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...*****RE: Export Clashes to txt file for import to excel speadsheet
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