AnsweredAssumed Answered

Distance mate in SW VB add-in

Question asked by Karl-Gustav Johansson on Jan 29, 2010
Latest reply on Feb 10, 2010 by Karl-Gustav Johansson

Hello,

 

I've created an add-in for SW in VB.net and it can move a sub assembly and also change one of the subassemblys distance mates.

The thing is that I want the add-in to be able to do this in realtime To move the subassembly goes realy fast but as soon as I call the edit distance mate function everything goes very slow even on a fast computer. Anyone has any ideas how to improve the performance or another approach that can give the same result? I am using SW 2008 SP5.

 

Here is the function I use to change the distance mate in the sub assembly with.

As you can see its pretty much from the example in SW API help with just the difference that it goes into edit assembly mode before changing the mate.

 

Thanks

 

 

Function changeDistanceMate(ByVal matePart As String, ByVal distanceValue As Double)

 

Dim swFeat As SldWorks.Feature

Dim swMate As SldWorks.Mate2

Dim swDispDim As SldWorks.DisplayDimension

Dim nNumMateEnt As Long

Dim swMateEnt() As SldWorks.MateEntity2

Dim vMateEntPar As Object

Dim nRetVal As Long

 

Dim swConfigMgr As SldWorks.ConfigurationManager

 

Dim swFeatMgr As SldWorks.FeatureManager

 

 

Dim swModelView As SldWorks.ModelView

 

 

swModel = swApp.ActiveDoc

swModelView = swModel.ActiveView

swFeatMgr = swModel.FeatureManager

swAssy = swModel

swConfigMgr = swModel.ConfigurationManager

 

 

 

 

swModel.SetAddToDB(

True)

swModel.SetDisplayWhenAdded(

False)

swModelView.EnableGraphicsUpdate =

False

swFeatMgr.EnableFeatureTree =

False

swFeatMgr.EnableFeatureTreeWindow =

False

 

 

'Set swApp = Application.SldWorks

 

'Set Part = swApp.ActiveDoc

 

'Set SelMgr = Part.SelectionManager

boolstatus = Part.Extension.SelectByID2(

"robot-1@visualisering", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

Part.EditAssembly()

Part.ClearSelection2(

True)

boolstatus = Part.Extension.SelectByID2(matePart,

"MATE", 0, 0, 0, False, 0, Nothing, 0)

 

'boolstatus = Part.Extension.SelectByID2("distanceMate2@robot-1@visualisering", "MATE", 0, 0, 0, False, 0, Nothing, 0)

 

swSelMgr = swModel.SelectionManager

swFeat = swSelMgr.GetSelectedObject5(1)

swMate = swFeat.GetSpecificFeature2

swDispDim = swMate.DisplayDimension2(0)

 

 

nNumMateEnt = swMate.GetMateEntityCount

 

ReDim swMateEnt(nNumMateEnt)

 

For i = 0 To nNumMateEnt - 1

swMateEnt(i) = swMate.MateEntity(i)

swComp = swMateEnt(i).ReferenceComponent

vMateEntPar = swMateEnt(i).EntityParams

 

Next i

 

Select Case swMate.Type

 

' Cannot change alignment on these mate types

 

Case 10

 

Exit Function

 

End Select

swModel.ClearSelection2(

True)

 

 

 

For i = 0 To nNumMateEnt - 1

 

' AssemblyDoc::EditMate2 requires mate entities

 

' to be selected with mark of 1 except for:

 

' swMateCAMFOLLOWER

 

' cam face --> 1

 

' cam follower face --> 8

 

' swMateSYMMETRIC

 

' symmetry faces --> 1

 

' symmetry plane --> 4

bRet = SelectMateEntity(swApp, swModel, swMateEnt(i), 1) : Debug.Assert(bRet)

 

Next i

 

' AssemblyDoc::EditMate2 requires mate feature to be last selected object

 

' mark is ignored

 

'swMateAlignCLOSEST

bRet = swFeat.Select2(

True, 0) : Debug.Assert(bRet)

swAssy.EditMate2( _

5, _

2, _

 

False, _

distanceValue, _

distanceValue, _

distanceValue, _

0.0#, _

0.0#, _

0, _

0, _

0, nRetVal)

 

' Do not assert because may overdefine assembly or other error

 

'Debug.Assert swAddMateError_NoError = nRetVal

 

 

 

' Do not assert because assemlby may have rebuild errors

 

' due to changing mate alignment

Part.EditAssembly()

 

'Part.ClearSelection2(True)

 

'bRet = swModel.EditRebuild3: 'Debug.Assert bRet

 

swModel.SetDisplayWhenAdded(

True)

swModel.SetAddToDB(

False)

swModelView.EnableGraphicsUpdate =

True

swFeatMgr.EnableFeatureTree =

True

swFeatMgr.EnableFeatureTreeWindow =

True

 

 

End Function

Outcomes