Problem with ComponentDefinition.Type

Problem with ComponentDefinition.Type

Anonymous
Not applicable
840 Views
4 Replies
Message 1 of 5

Problem with ComponentDefinition.Type

Anonymous
Not applicable

Hello All,

 

I use this rule to delete Sketched symbol if model of drawing is assy.

It is work 29 times in 30, but sometimes appear an error massage.

I have debuged the rule (with msg box), and it stop after ComponenetDefinition.Type.

I try to add this parameter to msg box. Usually I get a code (at part it is: 83886592, it works fine), but sometimes error message.

When I find a part what have this problem and create a new base view about it, the rule works fine.

So I cannot find any context between error messege and component of drawing.

How can I fixed this problem?

Any other way to make different assy and part?

 

 

SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition= oDrawDoc.SketchedSymbolDefinitions.Item("General tolerance")
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oSymbols As SketchedSymbols
If ThisDoc.ModelDocument.ComponentDefinition.Type = 100663808 Then

For Each oSymbol  In oSheet.SketchedSymbols
    If oSymbol.Definition.Name = "General tolerance" Then
        oSymbol.Delete
    Else 
    End If
Next

Return
End If

 

Component_def_error.JPG

 

0 Likes
Accepted solutions (1)
841 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor

Try this:

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oViews As DrawingViews = oSheet.DrawingViews
If oViews.Count = 0 Then Exit Sub Dim oDoc As ReferencedFileDescriptor = oViews(1).ReferencedFile If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub For Each oSymbol As SketchedSymbol In oSheet.SketchedSymbols If oSymbol.Definition.Name = "General tolerance" Then oSymbol.Delete() End If Next

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for your quick answer. Now I have no time, I am going to go holiday next week. After it I will test it.

0 Likes
Message 4 of 5

Anonymous
Not applicable

What can I do if I want to indentify a Sheet metal model.

The rule is the same, but at Sheet metal I want to do something.

That is why I use ex.

ThisDoc.ModelDocument.ComponentDefinition.Type <> 150995200

 

0 Likes
Message 5 of 5

Owner2229
Advisor
Advisor
Accepted solution

Here you go:

 

If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Do somehting
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes