Assembly constraints

Hello

In vba I make a program that opens in an assembly parts (of a bottle) and assembles them (complete bottle).

My problem comes to constrain the pieces in them. 

As it is the user who chooses these parts, the mix between the open pieces will change.e.g: flat bottom, rounded bottom, rounded square edge, straight square edge etc...

What I started by doing is to constrain the plans of each room.

 

Macro registration code

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Wreath face@Bague Plane 26-1@Assemblage Round Edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Plan of face@EP-BR-ST-1@Assemblage Round Edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

Dim myMate As Object

Set myMate = Part.AddMate3(0, 0, False, 0, 0, 0, 0.001, 0.001, 0, 0.5235987755983, 0.523598775983, False, longstatus)

Part.ClearSelection2 True

Part.EditRebuild3

 

boolstatus = Part.Extension.SelectByID2("Right Plan", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

boolstatus = Part.DeSelectByID("Right Plan", "PLANE", 0, 0, 0)

boolstatus = Part.Extension.SelectByID2("Wreath droite@Bague Plane 26-1@Assemblage Round Edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Plan of droite@EP-BR-ST-1@Assemblage Round Edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

Set myMate = Part.AddMate3(0, 0, False, 0, 0, 0, 0.001, 0.001, 0, 0.5235987755983, 0.523598775983, False, longstatus)

Part.ClearSelection2 True

Part.EditRebuild3

 

boolstatus = Part.Extension.SelectByID2("Plan_inf@Bague crown 26-1@Assemblage Round edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Plan_sup@EP-BR-ST-1@Assemblage Round Edge", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

Set myMate = Part.AddMate3(0, 1, False, 0.071, 0, 0, 0.001, 0.001, 0, 0.5235987755983, 0.5235987755983, False, longstatus)

Part.ClearSelection2 True

Part.EditRebuild3

 

We can see that there is a space between the two pieces of " 0.071"m and I don't know how to define it. (it will change for each set of parts so too restrictive especially since the part library will grow as you go along)

In my macro I intentionally put Y-shaped spaces to separate the parts when I import them (cf: image) so I know the space between the origin of the assembly and the center of gravity of my part. (is it the center of gravity that is taken into account when importing parts?)

Is it possible to recover the height of the room? (VBA variables)

 

Or any other ideas are welcome too!

 

Thank you 

JB


assemblage_bouteille.png

Hello

 

To know a value of a dimension, it would have to have the same name in all the parts, for example:

D1@Extrusion1

 

In this case, it's not very complicated, see this link:

http://help.solidworks.com/2012/English/api/sldworksapi/Get_Display_Dimension_Properties_Example_VB.htm

 

Or else to go through all the dimensions of a part:

http://help.solidworks.com/2012/English/api/sldworksapi/Iterate_Through_Dimensions_in_Model_Example_VB.htm

1 Like

Look in the API Help

GetBox Method (IComponent2) 

or 

GetPartBox Method (IPartDoc)

 

they return an array of coordinates corresponding to the wrapping cube

for the height following z => values(5) - values(2)

 

 

8 Likes

Hello

 

On the other hand, unless I'm mistaken, it's the origins that are superimposed by default when importing. Not the center of gravity.

Hi @ Jean-bapt

 

I ask myself the question?

you ask in a blend to be able to have the choice of configues #

 

if you create your assembly with x parameter

  • you have 4 sections
  1. Funds
  2. the bodies
  3. The passes
  4. Bottlenecks
  • In section 1 you have # types

 a_ flat bottom

 b_ rounded bottom

 c_ rounded square edge

 d_ straight square edge etc.

  •  In section 2 you have # types
  • a_b_c_d
  •  In section 3 you have # types
  • a_b_c_d
  •  In section 4 you have # types
  • a_b_c_d

Why not play on the assembly with fragmented parts

A common axis for this example case (constraint ref)

you put it all together

you make a splash by posing in each section (dotted rectangle)

the types corresponding to these sections

you hide the unwanted types

you gather your assembly to visualize

if it's OK for you registration 

You still have to delete the unwanted pieces (which are hidden) on this recording

enregistrement_ plan_nomenclature_ etc

 

(I hope I was clear enough in my explanation)

 

@+ ;-)

 

Hello Gt22,

 

Thank you for your answer!

(I was working on some other things for the last two weeks)

 

I didn't quite understand what you mean by:

"You make a splash by posing in each section (dotted rectangle)

the types corresponding to these sections

you hide the undesirable guys"

 

What I did in my macro is insert the pieces except that I want to insert them linked.

 

When you put the word "you" I would like the vba API to do it.

 

If you want I can show you what I did, there's nothing secret.

 

Like what:

Is it possible to insert pieces in an order and constrain them to the previously inserted piece?

 

Is it possible to link the dimensions of the parts together via API?

 

Thank you for your answers,

 

JB

1 Like

which version of SW are you on?

@+ ;-)

I'm on SolidWorks 2012 in 64 Bits

Hello

 

Here are the specifications of my program, I want the user to :

-          Choose predefined items from a library

-          Choose the heights of each element

-          Choose the width or diameter of the bottle

-          Choose the capacity of the bottle

-          Choose the type of glass (material)

 

There are things that I can see later, the most important thing is the modification of the height of the pieces and the width and length.

 

Attached is an assembly of a bottle that could exist and whose parameters I would like to vary.


assemblage_bouteille_carre_droit.sldasm