×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

CATIA Macro for Assembly Constraints

CATIA Macro for Assembly Constraints

CATIA Macro for Assembly Constraints

(OP)
I have the following CATIA Script that does the following job in the product document:

1. Asks the user to select target points (which are geometrical points and not from a sketch) where they want bolts to be inserted,
2. Retrieves the location of the part file of the bolt from the user,
3. Creates a level 1 product in the tree (i.e., a subassembly),
4. Inserts the bolts in the subassembly as many times as there were points selected in step 1.

Now, every part file of the bolt that is inserted has a geometrical point (which is different from sketch points) in it. I want the macro to add a coincidence constraint to each point in the parent part (that was selected by the user in step 1) with a point in each inserted part. How can I achieve this? Also, I will be working with many other bolts but each of them contains a geometrical point (like described above), so I want it to be generalised. I have very, very little knowledge about scripting macros, and I got the following script from the internet. I would appreciate it if anyone could help.

CODE --> CATScript

Sub CATMain()

'SELECT THE ACTIVE DOCUMENT
Dim mysel
set mysel = catia.activedocument.selection

'CREATE A FILTER SO THAT THE USER CAN SELECT POINTS ONLY
dim myfilter(0)
myfilter(0)="Point"

'TELL CATIA TO PROMPT THE USER TO SELECT THE POINTS
dim mypoints
mypoints = mysel.SelectElement3(myfilter,"Select the target points for insertion of parts",true,CATMultiSelTriggWhenUserValidatesSelection,false)

if (status = "Cancel") then exit sub

'COUNT THE POINTS 
for x=1 to mysel.count
set point=mysel.item(x).value
next

'RETRIEVE THE PATH OF THE PART FROM THE USER 
Dim strFilePath As String
 
'DISPLAY FILE OPEN DIALOG BOX
strFilePath = CATIA.FileSelectionBox("Select Part File", "*.CATPart", 0)
 
'IF USER CLICKED CANCEL (empty string is returned), EXIT THE PROGRAM
if strFilePath = "" Then Exit Sub

dim ofilesys as filesystem
set ofilesys=catia.filesystem

if (not ofilesys.fileexists(strfilepath)) then
'err.raise 9999,,sfilepath & ": This file does not exist."
msgbox "Error: The file does not exist."
else

dim arrayofvariantofbstr1(0)
arrayofvariantofbstr1(0)=strfilepath
dim partdocument1 as document
set partdocument1 = CATIA.ActiveDocument

'Get the Root Product from the Product document:
dim product1 as product
set product1 = partdocument1.product

Dim products1 as products
Set products1=product1.products

'CREATING A SUBASSEMBLY
Dim Product2 as product
Set Product2=products1.AddNewComponent("Product", "")

Dim products2 as products
Set products2 = product2.products

'INSERTING PARTS AS MANY TIMES
dim instancesss
for instancesss=1 to mysel.count
   products2.AddComponentsFromFiles arrayofvariantofbstr1,"All"
next

Msgbox "Parts succesfully inserted." & vbnewline & "No. of parts inserted: " & mysel.count, 0
end if
End Sub 

RE: CATIA Macro for Assembly Constraints

Hi,

If the links in the previous replies will help you getting the VBA objets and methods to do it, you also need to make your sub-assembly "not rigid". If it is rigid, then you can't constraint more than one bolt to parts outside of that sub-assembly. (You can, but it won't update in CATIA if they are all active).

regards
Thierry

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close