Expert PLM Consulting Services by Dassault Partner

A
B
O
U
T
 
U
S
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 :
O
U
R
 
P
L
M
 
C
O
N
S
U
L
T
A
N
T
S
 
A
R
E
Bilingual
Canadian/US Citizen
3DExperience strong knowledge
Average of 7 years in PLM
Worldwide relocation
Mechanical or Computer Engineers
Strong team spirit!
U
S
I
N
G
 
W
I
N
D
O
W
S
 
A
P
I
By Eric Neuville , Techso
W
a
r
n
i
n
g
s
I do not pretend to be a first class programmer.
Don’t shoot the messenger
Use at your own risk
C
l
i
m
b
i
n
g
 
t
h
e
 
T
r
e
e
This code will let the user
go up and down in CATIA
Spec tree using buttons in a form:
C
l
i
m
b
i
n
g
 
t
h
e
 
T
r
e
e
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
C
l
i
m
b
i
n
g
 
t
h
e
 
T
r
e
e
Create a new Form
Add 1 button
change its name to
CommandButtonUP
Change its caption to
UP
Double click the button
to define its code…
Private Sub CommandButtonUP_Click()
 
Module1.BringToFront
 
SendKeys "{UP}", True
End Sub
[…]
Private Sub UserForm_Initialize()
 
CATIA.ActiveWindow.Layout = catWindowSpecsOnly
End Sub
Private Sub UserForm_Terminate()
 
CATIA.ActiveWindow.Layout = catWindowSpecsAndGeom
End Sub
C
l
i
m
b
i
n
g
 
t
h
e
 
T
r
e
e
Make 4 other buttons:
DOWN
LEFT
RIGHT
HOME
And copy paste the code from Private Sub
Private Sub CommandButton
UP
_Click()
 
Module1.BringToFront
 
SendKeys "{
UP
}", True
End Sub
and adapt to 
DOWN
 / 
LEFT
 / 
RIGH
 / 
HOME
C
l
i
m
b
i
n
g
 
t
h
e
 
t
r
e
e
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.
D
i
s
a
s
s
e
m
b
l
e
This code will let the user run the
disassemble GSD function using
WINAPI as CATIA API is missing.
D
i
s
a
s
s
e
m
b
l
e
This is the logic we
want to use
CATPart
open?
End
Start
Start
Disassemble
Disassemble
Any
selection
?
Valid
selection?
Yes
Yes
Yes
No
No
No
Close
Disassemble
T
h
e
 
W
I
N
 
A
P
I
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
Info comes from MS help WEB,
or  
https://stackoverflow.com
T
h
e
 
W
I
N
 
A
P
I
Then add also the following lines
Private Const WS_DISABLED = &H8000000
Private Const BM_CLICK = &HF5
Dim hDisassemble As LongPtr
Dim hOKButton As LongPtr
Info comes from MS help WEB,
or  
https://stackoverflow.com
T
h
e
 
m
a
i
n
 
s
u
b
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
End Sub
I used spyxx from MS
VisualStudio to get this info
T
h
e
 
o
t
h
e
r
 
f
u
n
c
t
i
o
n
s
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
T
h
e
 
o
t
h
e
r
 
f
u
n
c
t
i
o
n
s
Checking if Selection is done
Function IsSelectionEmpty() As Boolean
result = False
If CATIA.ActiveDocument.Selection.Count = 0 Then result = True
IsSelectionEmpty = result
End Function
T
h
e
 
o
t
h
e
r
 
f
u
n
c
t
i
o
n
s
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
Y
o
u
r
e
 
d
o
n
e
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)
r
e
m
i
n
d
e
r
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.
Q
U
E
S
T
I
O
N
S
 
?
eneuville@techso.ca
indocti discant et ament meminisse periti
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.

  • PLM Consulting
  • Dassault Partner
  • 3DEXPERIENCE
  • CATIA
  • Montreal

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

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#