SolidWorks API Error
SolidWorks API Error
(OP)
Hi All.
I am doing a system where i want to put a code and a description of a item into the custom properties directly.
I have this source code, but have a error (type mismatch) every time when i want to use. Anybody can help me?
[]'s
Adriano
----------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim nRetVal As Long
Dim vNameArr As Variant
Dim vName As Variant
Dim bRet As Boolean
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject5(1) -> Error
Set swCustPropMgr = swFeat.CustomPropertyManager
I am doing a system where i want to put a code and a description of a item into the custom properties directly.
I have this source code, but have a error (type mismatch) every time when i want to use. Anybody can help me?
[]'s
Adriano
----------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim nRetVal As Long
Dim vNameArr As Variant
Dim vName As Variant
Dim bRet As Boolean
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject5(1) -> Error
Set swCustPropMgr = swFeat.CustomPropertyManager






RE: SolidWorks API Error
RE: SolidWorks API Error
RE: SolidWorks API Error
I agree with "SolidAir" you need to qualify that your selection is a Feature BEFORE assigning it to your "swFeat" variable. If you don't do this, that's going to cause a type mismatch every time there is a non-feature selection (e.g. a note, dimension, etc.). I don't have my API manual handy here at home so take a look at the documentation code samples. There should be an example in there on how to do this.
One additional thing, I'm fairly certain that you probably could achieve the end result you by assigning your selection to the ModelDoc2 variable. Drilling down to the "leaf" shouldn't be necessary.
Hope this helps out a bit.
Chris Gervais
Application Engineeer
CADD Edge