Adding GroundConstraint to more than one entity (simultaneously)

Adding GroundConstraint to more than one entity (simultaneously)

Anonymous
Not applicable
376 Views
5 Replies
Message 1 of 6

Adding GroundConstraint to more than one entity (simultaneously)

Anonymous
Not applicable
Hello,

I have a couple of SketchPoints in a Sketch and I all of them shall get the groundConstraint via VBA.

Of course I could use any loop in VBA and assign point by point the groundConstraint. But I want a solution wihtout using a loop.

What I tried to do is save all the points in a sketchPoints-Collection and then using GeometricConstraints.AddGround(PointCollection).
Well, unfortunately this doesn't work. Reading the help-File it seems that "GeometricConstraints.AddGround" can only handle on entity.
But when you are using the UI and select all the points with the mouse and then click on the butoon "GroundConstraint" then all the points get this constraint.

Maybe anyone has an idea how this could be done in VBA adn could help me.

Thanks in advance

Greetings Dennis
0 Likes
377 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
The UI hides much of what actually goes on "behind the scenes".

You'll have to add the ground constraints one entity at a time.
Of course, you could always write a Sub that loops through every object in an object collection that is passed to it as an argument...
e.g.

No error checking:

Public Sub AddGroundToCollection(oCol as ObjectColection)
Dim i as integer
For i = 1 to oCol.Count
oCol.Item(i).AddGround
next
End Sub
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thanks clemsoh for your response and code.

So think I have to use a loop, like yours.

Thought I could do it all by once.......

Greetings Dennis
0 Likes
Message 4 of 6

Anonymous
Not applicable


or you could get rid of the i and loop something like this:



Public Sub AddGroundToCollection(oCol as ObjectCollection)



Dim p as Point

For each p in oCol

p.AddGround

next p



End Sub



I like this better because you still have i to use elseware.

0 Likes
Message 5 of 6

Anonymous
Not applicable
And also take into account that
For Each - Next loop is distinctly faster
than For i=1 to... Next i loop.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks Josh and ALink for your reply.

The Each - Next Loop sound goods. I'll give it a try and watch if it's faster.

Greetings Dennis
0 Likes