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 .
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
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 .
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