Hello.
I would like to change the active sheet on a drawing using VBA-API, but I can't find any way to do it, I'm new to VBA-API. The best I cold manage was to use macro to change sheets, which worked, but did produce somr undesired effect.
The documentation states "You can regenerate a sheet only if it is displayed.", so it must be possible to change the displayed sheet.
My code so far
Public Sub change_sheet_parameter() Dim conn As IpfcAsyncConnection Dim cAC As CCpfcAsyncConnection Dim session As IpfcBaseSession Dim model1 As IpfcModel Dim sheetData As IpfcSheetData Dim sheetowner As IpfcSheetOwner Dim sheetInfo As IpfcSheetInfo Set cAC = New CCpfcAsyncConnection Set conn = cAC.Connect("", "", ".", 5) Set session = conn.session Dim oModelDescriptorCreate As New CCpfcModelDescriptor Dim oModelDescriptor As IpfcModelDescriptor name_w = "SHM-7457-004.drw" 'Name of the drawing Set oModelDescriptor = oModelDescriptorCreate.Create(EpfcMDL_DRAWING, name_w, Null) Set model1 = session.RetrieveModel(oModelDescriptor) Set sheetowner = model1 Dim oWindow As pfcls.IpfcWindow Set oWindow = session.OpenFile(oModelDescriptor) oWindow.Activate Set sheetInfo = sheetowner.GetSheetInfo(1) test_ = sheetInfo.Height MsgBox test_ 'The part where I would like to change the displayed sheet. sheetowner.RegenerateSheet (1) End Sub
Solved! Go to Solution.
So the answer was in the tutorials for VBAPI in the pfcDrawingExample.vb
In the "Create drawing views" example it clearly shows what command to use.
'Create drawing views '====================================================================== 'Function : createSheetAndViews 'Purpose : This function adds a new sheet to a drawing and ' creates three views of input model. '====================================================================== Public Sub createSheetAndViews(ByRef session As IpfcBaseSession, ByVal solidName As String) Dim model As IpfcModel Dim solidModel As IpfcModel Dim drawing As IpfcDrawing Dim sheetNo As Integer Dim modelDesc As IpfcModelDescriptor Dim matrix As CpfcMatrix3D Dim i, j As Integer Dim transF As IpfcTransform3D Dim pointLoc As IpfcPoint3D Dim genViewInstructions As IpfcGeneralViewCreateInstructions Dim proViewInstructions As IpfcProjectionViewCreateInstructions Dim view2D As IpfcView2D Dim outline As CpfcOutline3D Try '====================================================================== 'Get current model and check that it is a drawing '====================================================================== model = session.CurrentModel If model Is Nothing Then Throw New Exception("Model not present") End If If Not model.Type = EpfcModelType.EpfcMDL_DRAWING Then Throw New Exception("Model is not drawing") End If drawing = CType(model, IpfcDrawing) '====================================================================== 'Add new sheet to drawing '====================================================================== sheetNo = drawing.AddSheet() drawing.CurrentSheetNumber = sheetNo '====================================================================== 'Find the model in session or retrieve from disk '====================================================================== modelDesc = (New CCpfcModelDescriptor).CreateFromFileName(solidName) solidModel = session.GetModelFromDescr(modelDesc) If solidModel Is Nothing Then solidModel = session.RetrieveModel(modelDesc) If solidModel Is Nothing Then Throw New Exception("Unable to load Model " + solidName) End If End If '====================================================================== 'Add the model to drawing '====================================================================== Try drawing.AddModel(solidModel) Catch ex As Exception Throw New Exception("Unable to add Model " + solidName + " to drawing") End Try '====================================================================== 'Create a general view from the Z axis direction at a predefined 'Location '====================================================================== matrix = New CpfcMatrix3D For i = 0 To 3 For j = 0 To 3 If i = j Then matrix.Set(i, j, 1.0) Else matrix.Set(i, j, 0.0) End If Next Next transF = (New CCpfcTransform3D).Create(matrix) pointLoc = New CpfcPoint3D pointLoc.Set(0, 200.0) pointLoc.Set(1, 600.0) pointLoc.Set(2, 0.0) genViewInstructions = (New CCpfcGeneralViewCreateInstructions). _ Create(solidModel, sheetNo, pointLoc, transF) view2D = drawing.CreateView(genViewInstructions) '====================================================================== 'Get the position and size of the new view '====================================================================== outline = view2D.Outline '====================================================================== 'Create a projected view to the right of the general view '====================================================================== pointLoc.Set(0, outline.Item(1).Item(0) + (outline.Item(1).Item(0) _ - outline.Item(0).Item(0))) pointLoc.Set(1, (outline.Item(0).Item(1) + outline.Item(1).Item(1)) / 2) proViewInstructions = (New CCpfcProjectionViewCreateInstructions). _ Create(view2D, pointLoc) drawing.CreateView(proViewInstructions) '====================================================================== 'Create a projected view bellow the general view '====================================================================== pointLoc.Set(0, (outline.Item(0).Item(0) + outline.Item(1).Item(0)) / 2) pointLoc.Set(1, outline.Item(0).Item(1) - (outline.Item(1).Item(1) _ - outline.Item(0).Item(1))) proViewInstructions = (New CCpfcProjectionViewCreateInstructions). _ Create(view2D, pointLoc) drawing.CreateView(proViewInstructions) drawing.Regenerate() Catch ex As Exception MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString) End Try End Sub
So the answer was in the tutorials for VBAPI in the pfcDrawingExample.vb
In the "Create drawing views" example it clearly shows what command to use.
'Create drawing views '====================================================================== 'Function : createSheetAndViews 'Purpose : This function adds a new sheet to a drawing and ' creates three views of input model. '====================================================================== Public Sub createSheetAndViews(ByRef session As IpfcBaseSession, ByVal solidName As String) Dim model As IpfcModel Dim solidModel As IpfcModel Dim drawing As IpfcDrawing Dim sheetNo As Integer Dim modelDesc As IpfcModelDescriptor Dim matrix As CpfcMatrix3D Dim i, j As Integer Dim transF As IpfcTransform3D Dim pointLoc As IpfcPoint3D Dim genViewInstructions As IpfcGeneralViewCreateInstructions Dim proViewInstructions As IpfcProjectionViewCreateInstructions Dim view2D As IpfcView2D Dim outline As CpfcOutline3D Try '====================================================================== 'Get current model and check that it is a drawing '====================================================================== model = session.CurrentModel If model Is Nothing Then Throw New Exception("Model not present") End If If Not model.Type = EpfcModelType.EpfcMDL_DRAWING Then Throw New Exception("Model is not drawing") End If drawing = CType(model, IpfcDrawing) '====================================================================== 'Add new sheet to drawing '====================================================================== sheetNo = drawing.AddSheet() drawing.CurrentSheetNumber = sheetNo '====================================================================== 'Find the model in session or retrieve from disk '====================================================================== modelDesc = (New CCpfcModelDescriptor).CreateFromFileName(solidName) solidModel = session.GetModelFromDescr(modelDesc) If solidModel Is Nothing Then solidModel = session.RetrieveModel(modelDesc) If solidModel Is Nothing Then Throw New Exception("Unable to load Model " + solidName) End If End If '====================================================================== 'Add the model to drawing '====================================================================== Try drawing.AddModel(solidModel) Catch ex As Exception Throw New Exception("Unable to add Model " + solidName + " to drawing") End Try '====================================================================== 'Create a general view from the Z axis direction at a predefined 'Location '====================================================================== matrix = New CpfcMatrix3D For i = 0 To 3 For j = 0 To 3 If i = j Then matrix.Set(i, j, 1.0) Else matrix.Set(i, j, 0.0) End If Next Next transF = (New CCpfcTransform3D).Create(matrix) pointLoc = New CpfcPoint3D pointLoc.Set(0, 200.0) pointLoc.Set(1, 600.0) pointLoc.Set(2, 0.0) genViewInstructions = (New CCpfcGeneralViewCreateInstructions). _ Create(solidModel, sheetNo, pointLoc, transF) view2D = drawing.CreateView(genViewInstructions) '====================================================================== 'Get the position and size of the new view '====================================================================== outline = view2D.Outline '====================================================================== 'Create a projected view to the right of the general view '====================================================================== pointLoc.Set(0, outline.Item(1).Item(0) + (outline.Item(1).Item(0) _ - outline.Item(0).Item(0))) pointLoc.Set(1, (outline.Item(0).Item(1) + outline.Item(1).Item(1)) / 2) proViewInstructions = (New CCpfcProjectionViewCreateInstructions). _ Create(view2D, pointLoc) drawing.CreateView(proViewInstructions) '====================================================================== 'Create a projected view bellow the general view '====================================================================== pointLoc.Set(0, (outline.Item(0).Item(0) + outline.Item(1).Item(0)) / 2) pointLoc.Set(1, outline.Item(0).Item(1) - (outline.Item(1).Item(1) _ - outline.Item(0).Item(1))) proViewInstructions = (New CCpfcProjectionViewCreateInstructions). _ Create(view2D, pointLoc) drawing.CreateView(proViewInstructions) drawing.Regenerate() Catch ex As Exception MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString) End Try End Sub