Hello Mr. coder convert this code to vb.net

Hello Mr. coder convert this code to vb.net

Chandan_SharmaZ3CJW
Contributor Contributor
518 Views
7 Replies
Message 1 of 8

Hello Mr. coder convert this code to vb.net

Chandan_SharmaZ3CJW
Contributor
Contributor

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
If Not String.IsNullOrEmpty(prtNumber) Then
dwgSheet.Name = prtNumber
End If
End If
Next
End If
End Sub

0 Likes
519 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

That code looks like it will work in the ilogic environment. Are you finding an error? If so please post the error message of the more info tab. Are you trying to run this in visual studio?

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

Chandan_SharmaZ3CJW
Contributor
Contributor

vb.net visual studio.jpg

0 Likes
Message 4 of 8

Chandan_SharmaZ3CJW
Contributor
Contributor
Maybe I am not able to Declare Variable, it can be reason.
Please advise how can be solved.

0 Likes
Message 5 of 8

Cadkunde.nl
Collaborator
Collaborator

I think debugging should explain what is going wrong.

 

But on first sight:

you declare

Dim ModelFile as Partdocument

Then you say ModelFile = .FullDocumentName (which is a string, you can see that if you hoover over it with your mouse)

 

you are missing Dim modeldoc as Document

you are missing Dim prtNumber as String

 

iLogic is filling in these missing parts for you, but in visual studio that is not the case

0 Likes
Message 6 of 8

Chandan_SharmaZ3CJW
Contributor
Contributor

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
If Not String.IsNullOrEmpty(prtNumber) Then
dwgSheet.Name = prtNumber
End If
End If
Next
End If
End Sub

'' This is my iLogic code -Just I need to create dll file through visual studio-
so what step need to do , Please explain.

0 Likes
Message 7 of 8

Cadkunde.nl
Collaborator
Collaborator
Sub Main
If TypeOf g_inventorapplication.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = g_inventorapplication.ActiveDocument
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
Dim modelFile As String = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
Dim modelDoc As Document = g_inventorapplication.Documents.Open(modelFile, False)
Dim prtNumber As String = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
If Not String.IsNullOrEmpty(prtNumber) Then
dwgSheet.Name = prtNumber
End If
End If
Next
End If
End Sub
0 Likes
Message 8 of 8

Cadkunde.nl
Collaborator
Collaborator

oh and I don't know if that line "If Type Of ..... Then" works

I would use

 

If g_inventorapplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
0 Likes