AnsweredAssumed Answered

Adding a Global Variable linking to a custom properties.

Question asked by Arlene Garfield on Dec 19, 2019
Latest reply on Dec 23, 2019 by Arlene Garfield

I am creating a Global Variable linking it to a custom properties.  (I am using custom properties because it is easier to update then down the line on the equation is set.  just updating the global variable runs into issue if you don't know the the index location or the exact value and the one command that is suppose to search by name doesn't seem to work for VBA.)

 

Anyhow the add3 command work when I enter a hard value say like 3 but when I do the text for the custom properties it fails and adds nothing.

 

Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim Part As Object
Dim PlaneD As Double
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim swEqMgr As SldWorks.EquationMgr
Dim GV1 As String
Dim longEquation As Long
Dim value As Integer
Dim Name As String


Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
Set swEqMgr = swModel.GetEquationMgr


'RENAME FRONT AND TOP PLANES
boolstatus = swModel.Extension.SelectByID2(" FRONT", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, True, False, "DXF- FRONT")
boolstatus = swModel.Extension.SelectByID2("TOP", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, True, False, "ROW1-TOP")


swModel.ClearSelection2 True

'Gets and sets the User input for Overall Tool Width
Dim rspaceNum As Double
rspaceNum = InputBox("Specify DISTANCE BETWEeN DXF ROW PLANES, DEFAULT 30 INCHES")
Dim RSP As Double
RSP = CDbl(rspaceNum)
Dim rspace As Long
Dim RSPval As String
Dim RSPvalout As String
Dim RSPbool As Boolean

 

'setup custom properties and dxf plane global distance
Set swCustProp = swModelDocExt.CustomPropertyManager("")
rspace = swCustProp.Add3("DisBWR", swCustomInfoDouble, RSP, swCustomPropertyReplaceValue)
RSPbool = swCustProp.Get4("DisBWR", False, RSPval, RSPvalout)
boolstatus = swModel.Extension.SelectByID2("Equations", "EQNFOLDER", 0, 0, 0, False, 0, Nothing, 0)

'I run one or the other but not both as is shown below

longEquation = swEqMgr.Add3(0, """RowS"" =3", True, 2, Nothing) ' works

longEquation = swEqMgr.Add3(0, """RowS"" =DisBWR", True, 2, Nothing) ' Fails

 

 

boolstatus = swModel.ForceRebuild()
swModel.Save

end sub

 

So any clue on what I have done wrong?

Outcomes