×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks API Error

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

RE: SolidWorks API Error

Withoug running the code myself, I believe that if the selected is not a feature, then you will get this error.  I would suggest testing the selection first then if it is a feature set it equal.  Of course the Feature.CustomPropertyManager call is used with Weldment features.  Is that what you are doing or are you trying to set the document custom properties?

RE: SolidWorks API Error

Try "CreateObject" instead of "GetObject".

RE: SolidWorks API Error

Hi,

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources