Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
doc = ThisDoc.ModelDocument
If (doc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
MessageBox.Show("Это не файл сортамента", "iLogic")
Return
End If
Dim oDrawingDoc as DrawingDocument
Dim oPartDoc as Document
Dim oSheet As sheet
Dim oView1 as DrawingView
Dim oView2 as DrawingView
Dim oView3 as DrawingView
ViewScale = 1/2
'Ask to create drawing?
dwgQuery=MsgBox("Создать чертеж сортамента?", vbYesNo,"Выбирите действие")
If dwgQuery = vbYes Then
oPartDoc = ThisDoc.Document
'Define DWG Template File Location
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "d:\Программы\Autodesk_Inventor_2013\Templates\Шаблоны-Никитин\Сортамент.dwg", True)
'oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True)
oSheet = oDrawingDoc.Sheets.Item(1)
' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
'True = folded view
'False = flat pattern view
oBaseViewOptions.Add("SheetMetalFoldedModel", False)
'Define 2d view bottom left corner points for four views
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(10, 20) ' front view
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(20, 20) ' right view
oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)' top view
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, ViewScale,kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "Главный")
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint2, kFromBaseDrawingViewStyle, ViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint3, kFromBaseDrawingViewStyle, ViewScale)
End If
На пользовательском элементе создана кнопка. На кнопку помещаю код: Dim doc As Document = m_inventorApplication.ActiveDocument
If (doc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
MsgBox("Это не файл сортамента", , "myAddIn")
Return
End If
Dim oDrawingDoc As DrawingDocument
Dim oSheet As Sheet
Dim oView1 As DrawingView
Dim oView2 As DrawingView
Dim oView3 As DrawingView
Dim ViewScale As Double = 1 / 2
'Ask to create drawing?
Dim dwgQuery As Integer = MsgBox("Создать чертеж сортамента?", vbYesNo, "Выберите действие")
If dwgQuery = vbYes Then
'Define DWG Template File Location
oDrawingDoc = m_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, "d:\Программы\Autodesk_Inventor_2013\Templates\Шаблоны-Никитин\Сортамент.dwg", True)
'oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True)
oSheet = oDrawingDoc.Sheets.Item(1)
' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = m_inventorApplication.TransientObjects.CreateNameValueMap
'True = folded view
'False = flat pattern view
oBaseViewOptions.Add("SheetMetalFoldedModel", False)
'Define 2d view bottom left corner points for four views
Dim oPoint1 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(10, 20) ' front view
Dim oPoint2 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(20, 20) ' right view
Dim oPoint3 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(10, 15) ' top view
oView1 = oSheet.DrawingViews.AddBaseView(doc, oPoint1, ViewScale, ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "Главный")
oView2 = oSheet.DrawingViews.AddProjectedView(oView1, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, ViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oView1, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, ViewScale)
End If
После нажатия на кнопку инвентор зависает. Чего не хватает в коде для работы кнопки? Спасибо.
На какой строке в режиме отладки возникает проблема?В режиме отладки никаких ошибок не возникает.
oDrawingDoc создается корректно?Чертеж вообще не создается
Если документ чертежа не создается, выкинь из кода все, кроме команды на его создаение и добейся результата.Сделал так, как Вы посоветовали. Дохожу до момента вставки вида и тут косяк.
Потом добавишь постепенно все остальное.
Dim oView1 As DrawingView
Dim oView2 As DrawingView
Dim oView3 As DrawingView
Dim ViewScale As Double = 1 / 2
Dim oPoint1 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(10, 20) ' front view
Dim oPoint2 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(20, 20) ' right view
Dim oPoint3 As Point = m_inventorApplication.TransientGeometry.CreatePoint2d(10, 15) ' top view
oView1 = oSheet.DrawingViews.AddBaseView(pDoc, oPoint1, ViewScale, ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "Главный")
oView2 = oSheet.DrawingViews.AddProjectedView(oView1, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, ViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oView1, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, ViewScale)
Что делать?
Да, верно. Тип надо задать Point2d. Точки же двумерные!
Dim oPoint1 As Point2d = m_inventorApplication.TransientGeometry.CreatePoint2d(10, 20)
Sorry, не обратил внимание
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Укажите вид")
oX = ActiveSheet.View(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(1)
oY = ActiveSheet.View(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(2)
oZ = ActiveSheet.View(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(3)
ActiveSheet.View(oView.Name).View.SetIncludeStatus(oX, True)
ActiveSheet.View(oView.Name).View.SetIncludeStatus(oY, True)
ActiveSheet.View(oView.Name).View.SetIncludeStatus(oZ, True)
Хочу это правило переделать на VB.netIf m_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
pDoc = m_inventorApplication.ActiveDocument
Dim ActiveSheet As Sheet
ActiveSheet = pDoc.ActiveSheet
Dim oView As DrawingView
oView = m_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Укажите вид")
Dim oRefDoc As Object
oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oX As WorkAxis
Dim oY As WorkAxis
Dim oZ As WorkAxis
oX = ActiveSheet.DrawingViews(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(1)
oY = ActiveSheet.DrawingViews(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(2)
oZ = ActiveSheet.DrawingViews(oView.Name).ModelDocument.ComponentDefinition.WorkAxes(3)
ActiveSheet.DrawingViews(oView.Name).View.SetIncludeStatus(oX, True)
ActiveSheet.DrawingViews(oView.Name).View.SetIncludeStatus(oY, True)
ActiveSheet.DrawingViews(oView.Name).View.SetIncludeStatus(oZ, True)
Else
MessageBox.Show("Активным должен быть чертеж!")
End If
Появляется сообщение: приведение строки "Вид1" к типу "Integer" является недопустимым. Рекомендация: сделайте вспомогательную функцию, которая будет находить в списке видов чертежный вид с нужным вам именем - обычным перебором for each - next.Что то на подобие этого:
For Each oDrawView In oActiveSheet.DrawingViews
If oView.Name = "ВИД3" Then Exit For
Next
Что то на подобие этого:Почти. Номер нужно подсчитать, т.е. должно быть что-то типа:
Код: [Выделить]
For Each oDrawView In oActiveSheet.DrawingViews
If oView.Name = "ВИД3" Then Exit For
Next
Dim i As Integer
For i = 1 To oActiveSheet.DrawingViews.Count
If oView.Name = oActiveSheet.DrawingViews(i).Name Then Exit For
Next
В i порядковый номер вида...
Хочу это правило переделать на VB.netАлександр, у тебя уже есть нужный вид! Должно быть типа этого:
Пишу код:
oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oX As WorkAxis
Dim oY As WorkAxis
Dim oZ As WorkAxis
oX = oRefDoc.ComponentDefinition.WorkAxes(1)
oY = oRefDoc.ComponentDefinition.WorkAxes(2)
oZ = oRefDoc.ComponentDefinition.WorkAxes(3)
oView.SetIncludeStatus(oX, True)
oView.SetIncludeStatus(oY, True)
oView.SetIncludeStatus(oZ, True)
Dim i As IntegerСпасибо, Алексей, именно то, что нужно было.
For i = 1 To oActiveSheet.DrawingViews.Count
If oView.Name = oActiveSheet.DrawingViews(i).Name Then Exit For
Next
oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocumentС этим у меня вопросов нет.
Dim oX As WorkAxis
Dim oY As WorkAxis
Dim oZ As WorkAxis
oX = oRefDoc.ComponentDefinition.WorkAxes(1)
oY = oRefDoc.ComponentDefinition.WorkAxes(2)
oZ = oRefDoc.ComponentDefinition.WorkAxes(3)
oView.SetIncludeStatus(oX, True)
oView.SetIncludeStatus(oY, True)
oView.SetIncludeStatus(oZ, True)