在VBA im Solidworks中选择特定视图

时间:2015-07-28 04:20:20

标签: vba solidworks

我有一个宏,它使用以下代码在SolidWorks工程图中选择一个视图。

Set swDraw = swApp.ActiveDoc  
Set swView = swDraw.GetFirstView  
Set swView = swView.GetNextView  

如何更改此选项以选择名为" Drawing View1"?

的视图

3 个答案:

答案 0 :(得分:2)

假设您的swView对象属于iView类型,您可以使用GetName2方法获取名称。因此,您可以使用您已经使用的GetNextView方法枚举图形中的每个视图,并检查名称是否匹配。

它并没有很好地记录,但是对于它的值,GetNextView方法在枚举结束后返回空引用指针(例如vb中的nothing)。

Set swDraw = swApp.ActiveDoc  
Set swView = swDraw.GetFirstView  
Do While Not swView is Nothing
    If swView.GetName2 = "Drawing View1" then Exit Do
    Set swView = swView.GetNextView  
Loop

答案 1 :(得分:1)

  1. 使用此方法:
  2. 其中Name =“Drawing View1”
  3. Type =“DRAWINGVIEW”
  4. X,Y,Z = 0,如果不知道
  5. 返回类型(值)是布尔值
  6. Dim instance As IModelDocExtension
    value = instance.SelectByID2(Name, Type, X, Y, Z, Append, Mark, Callout, SelectOption)
    

答案 2 :(得分:0)

Set Part = swApp.OpenDoc6(drawpathandfile, 3, 0, "", longstatus, longwarnings)
Dim swDrawing   As Object
Set swDrawing = Part
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 33
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "Drawing View1", False, longstatus
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized