×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Mate components in an assembly and align axes API Macro

Mate components in an assembly and align axes API Macro

Mate components in an assembly and align axes API Macro

(OP)
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

RE: Mate components in an assembly and align axes API Macro

(OP)
up! :(

RE: Mate components in an assembly and align axes API Macro

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:
http://help.solidworks.com/2010/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.iassemblydoc~addmate3.html

and

http://help.solidworks.com/2010/english/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swMateType_e.html

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

-handleman, CSWP (The new, easy test)

RE: Mate components in an assembly and align axes API Macro

(OP)
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!  

RE: Mate components in an assembly and align axes API Macro

You want swmateCOORDINATE not swmateCOINCIDENT.
 

-handleman, CSWP (The new, easy test)

RE: Mate components in an assembly and align axes API Macro

(OP)
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..

 

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!


Resources