Expert PLM Consulting Services by Dassault Partner

Slide Note
Embed
Share

Montreal and Toulouse-based PLM consulting company, a Dassault partner with a global presence across America, Asia, and Europe, offering services by a team of 50 bilingual IT and PLM consultants with strong expertise in 3DEXPERIENCE projects. They specialize in mechanical and computer engineering, emphasizing teamwork and excellence in their work. The provided guide showcases how to navigate CATIA Spec tree efficiently using VBA code in CATIA.


Uploaded on Sep 22, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. ABOUT US IT/PLM consulting services company Dassault Partner Located in Montreal (HQ) and Toulouse, France International presence (America, Asia, Europe) 50 IT and PLM consultants Strong references on 3DEXPERIENCE Projects 3 Centers of Excellence : OUR PLM CONSULTANTS ARE Bilingual Canadian/US Citizen 3DExperience strong knowledge Average of 7 years in PLM Worldwide relocation Mechanical or Computer Engineers Strong team spirit!

  2. USING WINDOWS API By Eric Neuville , Techso

  3. Warnings I do not pretend to be a first class programmer. Don t shoot the messenger Use at your own risk

  4. Climbing the Tree This code will let the user go up and down in CATIA Spec tree using buttons in a form:

  5. Climbing the Tree Create your VBA Module and copy /paste the following text into it Sub CATMain() UserForm1.Show End Sub Sub BringToFront() On Error Resume Next AppActivate CATIA.Caption On Error GoTo 0 End Sub

  6. Climbing the Tree Private Sub CommandButtonUP_Click() Module1.BringToFront SendKeys "{UP}", True End Sub Create a new Form Add 1 button change its name to CommandButtonUP Change its caption to UP [ ] Private Sub UserForm_Initialize() CATIA.ActiveWindow.Layout = catWindowSpecsOnly End Sub Double click the button to define its code Private Sub UserForm_Terminate() CATIA.ActiveWindow.Layout = catWindowSpecsAndGeom End Sub

  7. Climbing the Tree Make 4 other buttons: And copy paste the code from Private Sub Private Sub CommandButtonUP_Click() Module1.BringToFront SendKeys "{UP}", True End Sub DOWN LEFT RIGHT HOME and adapt to DOWN / LEFT / RIGH / HOME

  8. Climbing the tree Final touch: Make the Form1 non modal so you can do stuff in CATIA while the form is active This tree tool can be used to find the parent of a selected object as sometimes we re dealing with occurrence and going up the tree is not that easy, also in a Part, this can help select the parent of an axis system or open/reduce geometrical set.

  9. Disassemble This code will let the user run the disassemble GSD function using WINAPI as CATIA API is missing.

  10. Disassemble Start Start This is the logic we want to use End Disassemble Disassemble No CATPart open? Yes Valid selection? Yes Any selection ? Yes No Close No Disassemble

  11. The WIN API Info comes from MS help WEB, or https://stackoverflow.com OK, create a VBA macro And paste this code into a new module Private Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As LongPtr, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long Private Declare PtrSafe Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongPtr, lParam As LongPtr) As Long Private Declare PtrSafe Function SetForgroundWindow Lib "user32.dll" Alias "SetForgroundWindowA" (ByVal hWnd As LongPtr) As LongPtr Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As LongPtr) As LongPtr

  12. The WIN API Info comes from MS help WEB, or https://stackoverflow.com Then add also the following lines Private Const WS_DISABLED = &H8000000 Private Const BM_CLICK = &HF5 Dim hDisassemble As LongPtr Dim hOKButton As LongPtr

  13. The main sub OK so first we check that CATIA is open and the selection is OK and we click OK if the button is not disabled Sub CATMain() If IsCATIAPartOpen And Not (IsSelectionEmpty) Then CATIA.StartCommand "Disassemble" While hDisassemble = 0 hDisassemble = FindWindow("#32770", "Disassemble") CATIA.RefreshDisplay = True Wend If Not (CheckOKButtonDisable) Then SendMessage hOKButton, BM_CLICK, 0, 0 End If End If I used spyxx from MS VisualStudio to get this info End Sub

  14. The other functions Checking if a CATPart is open Function IsCATIAPartOpen() As Boolean Dim myDoc 'As CATIADocument Set myDoc = CATIA.ActiveDocument result = False If TypeName(myDoc) = "PartDocument" Then result = True IsCATIAOpen = result End Function

  15. The other functions Checking if Selection is done Function IsSelectionEmpty() As Boolean result = False If CATIA.ActiveDocument.Selection.Count = 0 Then result = True IsSelectionEmpty = result End Function

  16. The other functions Checking if the Disassemble OK button is enable Function CheckOKButtonDisable() As Boolean While hOKButton = 0 hOKButton = FindWindowEx(hDisassemble, 0, "Button", "OK") Wend Dim myOKStyle As LongPtr myOKStyle = 0 myOKStyle = GetWindowLong(hOKButton, GWL_STYLE) result = (myOKStyle And WS_DISABLED) <> 0 CheckOKButtonDisable = result End Function

  17. Youre done So you can create a sketch in your part with a rectangle in it Select the sketch once it is done and run the script See how the script react when you select something that can not be disassembled (a plane)

  18. reminder The purpose of this presentation is to present tools so user who are not familiar with WIN API could start to investigate and have fun. It is recommended to manage some kind of error handling when using WIN API in order to avoid infinite loop. Please check the VB code from weagan22 on eng-tips.com for a tree reordering solution.

  19. QUESTIONS ? eneuville@techso.ca indocti discant et ament meminisse periti

Related


More Related Content