Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Mate components in an assembly and align axes API Macro

Status
Not open for further replies.

Ponza85

Bioengineer
Feb 3, 2011
6
Dear all,

I'm a few skilled SolidWorks user (version 2010) and I'm beginning to face the API Macro world.

I have to create a very complex VB Macro, and I already have problems in the first part of it.

This is the task of this Macro's part:

I create an empty assembly and I have to add some Parts. The Origin of each part must be mated with the assembly Origin AND I have to enable the Align Axes.

If I record a Macro while I do this procedure manually and I use the SAME code created, it doesn't work o_O.

Anyway, I could elaborate the code here below, which allow to create a Mate between all Origins, but Parts are not aligned to axes, they move around the only point related and the assembly results Under-defined.

Can you help me please?
How can I set the Align Axes ON?


I'm getting crazy about it...hope you'll find a solution! :)




CODE:

Option Explicit
'Dichiarazione variabili pubbliche
Public CaseCode As String 'Codice Caso

'***************************************
'*****Comando di uscita della macro*****
'***************************************
Private Sub cmdExit_Click()

End

End Sub


'********************************************
'*****Comando di creazione degli assiemi*****
'********************************************

Private Sub cmdAssembly_Click()

Dim SelectionManager As Object
Dim swApp As Object
Dim Assembly As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim Feature As SldWorks.AssemblyDoc

Dim FemurAssembly As String
Dim FemurPiramyd, FemurCut, FemurTrim, FileDir As String
Dim longstatus As Long, longwarning As Long
Dim mateRef1 As Object, mateRef2 As Object, mateRef3 As Object

Dim swFeatMgr As SldWorks.FeatureManager
Dim swSelMgr As SldWorks.SelectionMgr
Dim strMateRefName As String
Dim swFeature As SldWorks.Feature
Dim rebuild As Boolean

'*****************************************************
'OPEN PARTS

FileDir = "C:\Documents and Settings\utente\Desktop\Prove SolidWorks\Parti originali\"

Set swApp = Application.SldWorks

Set Part = swApp.OpenDoc("C:\Documents and Settings\utente\Desktop\Prove SolidWorks\Parti originali\tibia.SLDPRT", 1)
swApp.OpenDoc "tibia.SLDPRT", 1

Set Part = swApp.OpenDoc("C:\Documents and Settings\utente\Desktop\Prove SolidWorks\Parti originali\punta.SLDPRT", 1)
swApp.OpenDoc "punta.SLDPRT", 1


'*****************************************************
'TEMPLATE & SAVING

Set Assembly = swApp.NewDocument("C:\Documents and Settings\All Users\Dati applicazioni\SolidWorks\SolidWorks 2010\templates\Assieme.asmdot", 0, 0#, 0#)
Assembly.SaveAs2 "C:\Documents and Settings\utente\Desktop\Prove SolidWorks\Parti originali\assieme.SLDASM", 0, False, False

Set Assembly = swApp.ActiveDoc

Set SelMgr = Assembly.SelectionManager
Set swFeatMgr = Assembly.FeatureManager


'******************************************************
'ADDING COMPONENTS

Assembly.AddComponent "tibia.SLDPRT", 0, 0, 0
boolstatus = Assembly.Extension.SelectByID2("tibia-1@assieme", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Assembly.UnfixComponent
Assembly.ClearSelection2 True

Assembly.AddComponent "punta.SLDPRT", 0, 0, 0



'*****************************************
'SELECTION & MATE


Set Assembly = swApp.ActiveDoc

boolstatus = Assembly.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Assembly.Extension.SelectByID2("Point1@Origine@punta-1@assieme", "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)


Dim myMate As Object
Set myMate = Assembly.AddMate3(0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, longstatus)


Assembly.ClearSelection2 True
rebuild = Assembly.EditRebuild3


boolstatus = Assembly.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Assembly.Extension.SelectByID2("Point1@Origine@tibia-1@assieme", "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)



Set myMate = Assembly.AddMate3(0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, longstatus)
Assembly.ClearSelection2 True
rebuild = Assembly.EditRebuild3





'*******************************************

Assembly.SaveAs2 "C:\Documents and Settings\utente\Desktop\Prove SolidWorks\Parti originali\assieme.SLDASM", 0, False, False


'*****************************************


End Sub
 
Replies continue below

Recommended for you

Look at the API help (Help->API Help from the main SolidWorks window). Look at the arguments for the AddMate3 function.

Recorded macros are generally not so useful in SolidWorks. Per my experience anyway.

Please see:

and


And please don't bump your posts. Have some daggum patience.

-handleman, CSWP (The new, easy test)
 
In the AddMate3 function, if I use 0, 0 for the first 2 parametres (they correspond to Coincident and Aligned), it doesn't work.

I think that that Aligned refers to the possible positions of a part (Aligned or Antialigned) and NOT to the axes alignment.

Can anyone help me?
Thanks!
 
You want swmateCOORDINATE not swmateCOINCIDENT.


-handleman, CSWP (The new, easy test)
 
boolstatus = Assembly.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Assembly.Extension.SelectByID2("Point1@Origine@tibia-1@assieme", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Assembly.Extension.SelectByID2("Point1@Origine@punta-1@assieme", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)

Set myMate = Assembly.AddMate3(20, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, longstatus)
Assembly.ClearSelection2 True
Assembly.EditRebuild3



if I use that (swMateCOORDINATE that is enum 20), no Mate is created..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor