function booleanFeature.add with Visual Basic

 

 Hello everybody

 

I try to do a substract between two solids.

I created a DocumentPart.

I copy two parts on this new document.

the first created a model in objDoc.Models.

the second add a Item in objDoc.Constructions.CopyConstructions

and add a item in objDoc.Models(1).Features

 

So, I process this function :

objDoc.Models.Item(1).BooleanFeatures.Add with goods parameters but it fails!

 

I don't understand. Does somebody can help me?

 

thanks a lot

 

Xavier FAURE

Code :

Module ModuleVolume

 

Sub Main()

'Declare the program variables.

Dim objApp As Object = Nothing

Dim objDocs As Object = Nothing

 

'Turn on error handling.

On Error Resume Next

 

'Connect to a running instance of Solid Edge.

objApp = GetObject(, "SolidEdge.Application")

If objApp Is Nothing Then

'Error message

MsgBox("The Application is closed. The program is going to open it.")

'Start Solid Edge.

objApp = CreateObject("SolidEdge.Application")

End If

 

'Turn off error handling.

On Error GoTo 0

 

'Make the application window visible.

objApp.Visible = True

 

'Access the Documents collection.

objDocs = objApp.Documents

 

Dim objDoc As Object

 

'Find out if any documents are open.

If objDocs.Count = 0 Then

'Add an Part document.

objDoc = objDocs.Add("SolidEdge.PartDocument")

Else

'Access the currently open document.

'MsgBox("Connection of part which is opened")

objDoc = objApp.ActiveDocument

End If

 

Dim objModel As SolidEdgePart.Model = objDoc.Models(1)

MsgBox("Number of shells ( in Models(1).Body ) : " + objModel.Body.Shells.Count.ToString)

MsgBox("Number of features : " + objModel.Features.Count.ToString)

Dim objConstructions As SolidEdgePart.Constructions = objDoc.Constructions

MsgBox("Number of constuctions : " + objConstructions.Count.ToString)

Dim objCopyConstructions As SolidEdgePart.CopyConstructions = objConstructions.CopyConstructions

MsgBox("Number of CopyConstructions : " + objCopyConstructions.Count.ToString)

 

Dim objBooleanFeatures As SolidEdgePart.BooleanFeatures = objDoc.Models.Item(1).BooleanFeatures

 

'The number of solid to do the boolean opertation

Dim NumberOfTools As Integer = 1

'A array which contains these solids

Dim Tools() As Object = {objConstructions.Item(1).Body}

'A member of the BooleanFeatureConstants constant set that specifies the type of Boolean operation to perform.

Dim Operation As SolidEdgePart.BooleanFeatureConstants = SolidEdgePart.BooleanFeatureConstants.seBooleanSubtract

 

MsgBox("Clic on Ok to process the function")

 

'Process the boolean fonction

objBooleanFeatures.Add(NumberOfTools, Tools, Operation)

 

MsgBox("It's Ok")

 

End Sub

End Module

 

 

Posted by: Xavier FAURE
Post date: 7/3/2008 1:28:58 AM

13 REPLIES

RE: function booleanFeature.add with Visual Basic

 

Hi Xavier,

change the last lines of code to the following:

         'The number of solid to do the boolean opertation

        Dim NumberOfTools As Integer = 1

 

        'A member of the BooleanFeatureConstants constant set that specifies the type of Boolean operation to perform.

        Dim Operation As SolidEdgePart.BooleanFeatureConstants = SolidEdgePart.BooleanFeatureConstants.seBooleanSubtract

 

        MsgBox("Clic on Ok to process the function")

 

        'Process the boolean fonction

        objBooleanFeatures.Add(NumberOfTools, objCopyConstructions.Item(1), Operation)

 

I tried to get it to work with multiple constructions but couldn't - if you need to subtract more than one construction at a time let me know and I can look again.

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 7/3/2008 1:53:26 AM

RE: function booleanFeature.add with Visual Basic

 

Thanks a lot.

I have searched all the day, I have registered on 5 forums and you are my first answer. Thanks!

It works! But when I look at the windows I see the BooleanFeature but also the second part which I have copied. Why?

How Can I save it with VB without optional parameters?

Thanks

xavier

 

 

Posted by: Xavier FAURE
Post date: 7/3/2008 2:35:54 AM

RE: function booleanFeature.add with Visual Basic

 

Hi

I 'm sorry I have an other problem. I fail to change the name of the CopiedPart in objDoc.Models.Item(1).Features.Item(1).FamilyOfPartsMember.

Can you help me?

I have found the method visible. It's ok.

And I needn't to do a intersection of  several solid bodies.

Thanks

Xavier

 

 

Posted by: Xavier FAURE
Post date: 7/3/2008 2:59:47 AM

RE: function booleanFeature.add with Visual Basic

 

Hi Xavier,

'Thanks a lot'. - no worries

Solid Edge automatically hides the part copy if you work interactively, you will need to hide it with an API call (probably objCopyConstructions.Item(1).Visible = False)

I'm not sure what you mean with the optional parameters - if you mean saving the document then there are no parameters for the Save() method. Do you mean this, or do you mean changing the parameters for the second part?

Cheers

Calum

 

[Looks like you were quicker than me ]

 

Posted by: Calum McLellan
Post date: 7/3/2008 3:05:19 AM

RE: function booleanFeature.add with Visual Basic

 

Hi Xavier,

is this what your looking for?objModel.Features.Item(1).Name = "TESTING"

this renames the feature in the edge bar. I'm not sure if this is what you need as I can't open the file you posted (academic license).

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 7/3/2008 3:33:47 AM

RE: function booleanFeature.add with Visual Basic

 

Thanks!

In fact, if I write objDoc.Save(), SolidEdge opens a window and I must to clic a first time on Ok in order to check the properties, then a second time in order to write the name of the file and then a third time because he says that there is part which have the same name ( I don't understand this because I have change name's parts ... It's strange)

Is it possible to automate this manipulation?

Have a good afernoon and thanks for your help, you are the only one!

Xavier

 

Posted by: Xavier FAURE
Post date: 7/3/2008 3:40:07 AM

RE: function booleanFeature.add with Visual Basic

Hi Xavier,

 

use SaveAs() the first time to set the path for the document, and the Save() after that. If you set Application.DisplayAlerts to false then all messages will be suppressed.

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 7/3/2008 3:54:31 AM

RE: function booleanFeature.add with Visual Basic

 

Hi Calum

It's perfect! It works! You're the best.

Do you know how I can close a documentPart?

Thanks

 

Xavier

 

Posted by: Xavier FAURE
Post date: 7/7/2008 12:09:35 AM

RE: function booleanFeature.add with Visual Basic

I'm sorry Calum but I have a other problem

 

I want know to do the intersectionCurve between the first part and the second part ( the first is a model and the second is a copyConstruction )

 

I have understood I have just to call :

 

objDoc.Models.Item(1).IntersectionCurves.Add(FaceSet1,FaceSet2)

 

But it doesn't work.

 

I have remplaced faceSet1 by objDoc.Models.Item(1).Features.Item(1).Faces(FeatureTopologyQueryTypeConstants.igQueryAll)

I have remplaced faceSet2 by objDoc.Constructions.CopyConstructions.Item(1).Faces(FeatureTopologyQueryTypeConstants.igQueryAll)

 

Have you got a idea?

 

Thanks

 

Xavier

 

 

 

 

Posted by: Xavier FAURE
Post date: 7/7/2008 1:17:02 AM