Im trying add force normal to face. I divide face, and select part which I want add force.
This is my construction. On right you can see divide part of face, which is selected, but force didnt add.
This is bit of my main code:
model.ClearSelection2(True)
model.Extension.SelectByID2("", "FACE", x / 1000, y / 1000, z / 1000, True, 0, Nothing, 0)
Dim selFace As Object
selFace = model.SelectionManager.GetSelectedObject6(2, -1)
Dim DistanceValues As Object = Nothing
Dim ForceValues As Object = Nothing
Dim beamArray As Object() = {selFace}
Dim data(6) As Double
Dim ComponentValues As Object
data(0) = 1.0#
data(1) = 1.0#
data(2) = 1.0#
data(3) = 1.0#
data(4) = 1.0#
data(5) = 1.0#
ComponentValues = data
swsCWForce = swsStudy.LoadsAndRestraintsManager.AddForce3(swsForceType_e.swsForceTypeNormal, 0, 2, 0, 0, 0, (DistanceValues), (ForceValues), False, False, 0, 0, 0, 5.0#, (ComponentValues), False, False, (beamArray), Nothing, False, errCode)
I have error from swsForceError_e: swsForceErrorApplyNormalForceToFacesAndShellEdges <> You can only apply normal force to faces and shell edges.
Probably I give wrong argument of function addForce3(..), but I dont know what is wrong.
Here I got code for my test application, which work. But in this application I dont divide face.
SolidworksApi/macrosImports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.cosworks
Imports System.ComponentModel
Imports System.IO
Imports System.Threading
Public Class Form1
Dim swApp As SldWorks
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim swSelMgr As SelectionMgr
Dim COSMOSWORKS As Object
Dim COSMOSObject As CwAddincallback
Dim swsActDoc As CWModelDoc
Dim swsStudyMngr As CWStudyManager
Dim swsStudy As CWStudy
Dim swsCWForce As CWForce
Dim selFace As Object
Dim errCode As Integer
Dim DistanceValues As Object = Nothing
Dim ForceValues As Object = Nothing
Dim ComponentValues As Object
Dim data(6) As Double
Try
swApp = GetObject(Nothing, "SldWorks.application")
Catch ex As Exception
swApp = CreateObject("SldWorks.application")
End Try
'Dim sAddinName As String = Application.StartupPath & "\\cosworks.dll"
'swApp.LoadAddIn(sAddinName)
swApp.CloseAllDocuments(True)
swApp.Visible = True
Dim swModel As ModelDoc2
swModel = swApp.NewPart()
swModel.Insert3DSketch2(False)
Dim line1 As SketchLine = swModel.CreateLine2(0, 0, 0, 0, 0, 100 / 1000)
line1.Select(False)
swModel.Insert3DSketch2(True)
Dim pt1 As SketchPoint = line1.GetStartPoint2()
line1.Select(False)
pt1.Select(True)
Dim plane As Entity = swModel.CreatePlanePerCurveAndPassPoint3(True, True)
pt1.Select(False)
plane.Select(False)
Dim sketchMgr = swModel.SketchManager
sketchMgr.InsertSketch(False)
sketchMgr.CreateLine(-10 / 1000, 10 / 1000, 0, 10 / 1000, 10 / 1000, 0)
sketchMgr.CreateLine(10 / 1000, 10 / 1000, 0, 10 / 1000, -10 / 1000, 0)
sketchMgr.CreateLine(10 / 1000, -10 / 1000, 0, -10 / 1000, -10 / 1000, 0)
sketchMgr.CreateLine(-10 / 1000, -10 / 1000, 0, -10 / 1000, 10 / 1000, 0)
sketchMgr.InsertSketch(True)
swModel.Extension.SelectByID2("Szkic" & "1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
swModel.Extension.SelectByID2("Szkic 3D1", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
Dim featureMgr As FeatureManager = swModel.FeatureManager
featureMgr.InsertProtrusionSwept4(False, False, 0, True, False, 0, 0, False, 0, 0, 0, 0, True, False, False, 0, False, False, 0, 0)
Me.WindowState = FormWindowState.Minimized
' Get the SOLIDWORKS Simulation object
' Thread.Sleep(5000)
COSMOSObject = swApp.GetAddInObject("SldWorks.Simulation")
COSMOSWORKS = COSMOSObject.CosmosWorks
' Open and get active document
swsActDoc = COSMOSWORKS.ActiveDoc()
' Create new static study
swsStudyMngr = swsActDoc.StudyManager()
swsStudy = swsStudyMngr.CreateNewStudy("Static", swsAnalysisStudyType_e.swsAnalysisStudyTypeStatic, swsMeshType_e.swsMeshTypeSolid, errCode)
' Select face of solid
Dim LBCMgr As CWLoadsAndRestraintsManager
LBCMgr = swsStudy.LoadsAndRestraintsManager
swSelMgr = swModel.SelectionManager
If swModel.Extension.SelectByID2("", "FACE", 0, 0, 100 / 1000, True, 0, Nothing, 0) Then
End If
selFace = swSelMgr.GetSelectedObject6(2, -1)
Dim beamArray As Object() = {selFace}
data(0) = 1.0#
data(1) = 1.0#
data(2) = 1.0#
data(3) = 1.0#
data(4) = 1.0#
data(5) = 1.0#
ComponentValues = data
swsCWForce = LBCMgr.AddForce3(swsForceType_e.swsForceTypeNormal, 0, 2, 0, 0, 0, (DistanceValues), (ForceValues), False, False, 0, 0, 0, 5.0#, (ComponentValues), False, False, (beamArray), Nothing, False, errCode)
End Sub
End Class
