issue while making section view with iLogic

issue while making section view with iLogic

Anonymous
Not applicable
2,057 Views
5 Replies
Message 1 of 6

issue while making section view with iLogic

Anonymous
Not applicable

hi friends,

I am trying to make a drawing of an assembly using iLogic, my efforts to make base view and side/top views were successful  

but when i try to get section view i get nothing except an error message .

with this code runing i get base view and top view in buttom of that but not section view. 

 

i have to mention that this code is based on some parameters that i have in my design. such as "Height" and "Length". also the function " StructureView" just suppresses some parts to get internal parts in view.

 

I'm using the code below:

 

'RDS
'RDS dims:
Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports Inventor.DrawingViewTyoeEnum
Imports Inventor.PointIntentEnum
Imports Inventor.DimensionTypeEnum
Imports Inventor.DrawingCurveSegmentEnum
Imports Inventor.DrawingCurveEnum
Imports Inventor.CurveTypeEnum

Sub Main()
    'RDS dims in mm
    Dim sheetheight As Integer = 297    'sheet size A3
    Dim sheetwidth As Integer = 420      'sheet size A3
    Dim tableheight As Integer = 51        'type A
    Dim tablewidth As Integer = 160          'type A
    Dim borderoffset  As Integer = 10    'rounded up
    Dim viewdis  As Integer =10      'selective
    Dim baseviewheight As Integer = Height
    Dim baseviewwidth As Integer = Length
    Dim fitspaceheight As Integer = sheetheight -tableheight - (2*borderoffset)-(3*viewdis)
    Dim fitspacewidth As Integer = sheetwidth- (2*borderoffset)-(2*viesdis)-50
    Dim Hscale As Double = Height/fitspaceheight
    Dim Wscale As Double = Length/fitspacewidth
    Dim scale As Double 
      If Wscale> Hscale Then
      scale=Wscale
      Else If Hscale>Wscale Then
      scale=Hscale
      Else If Hscale=Wscale Then
      scale=Hscale
      End If
    'RDS ends dim%
  
  AskCreateDrawing = MessageBox.Show("if you would like to create a  STRUCTURE drawing from this view, please hit YES and then fill up comming filds (RDS)  ", "Sajiran-Beta Partitioning System",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
  'RDS asks for plot:
  
  If AskCreateDrawing = vbYes Then
  'RDS asks for project name & code and also view name
    iProperties.Value("Project", "Project") = InputBox("Enter Project Name:", "Sajiran-Beta Partitioning System", "Sajiran")
    iProperties.Value("project", "Stock Number") = InputBox("Enter Project Code:", "Sajiran-Beta Partitioning System", "1234")
    iProperties.Value("Status", "Status") = InputBox("Enter View Name:", "Sajiran-Beta Partitioning System", "View 1")

    'RDS alter to structure
    Structureview (True)
    

    'RDS inserts calculated scale into rule:
    Dim DrawingViewScale As Double 
    DrawingViewScale = 1/scale
    
    Dim AssemblyDocName As String 
    AssemblyDocName = ThisDoc.FileName(False) 'without extension
    
    Assem_DrawingDoc = CreateDrawing_PlaceViews (AssemblyDocName, DrawingViewScale, "Top_Section", True, oBaseView, oRightSideView, oProjectView, oView4)
    
    'RDS Save As oDrawingDoc (Path and File Name) :
    oPartPath = ThisDoc.Path
    oPartPathLength = Len(oPartPath)
    oDrawingPath = Left(oPartPath, oPartPathLength - 7)
    
    oDrawingDoc = oDrawingPath & "\" & AssemblyDocName & ".idw"
      
    Assem_DrawingDoc.SaveAs(oDrawingDoc, False)
    'RDS Close the Template Drawing:
    Assem_DrawingDoc.Close(True)
    'RDS Open the Newly Saved Drawing:
    DrawingDoc = ThisApplication.Documents.Open(oDrawingDoc, True)
    
    Structureview (False)  
  End If


End Sub

'RDS dims function:
Function CreateDrawing_PlaceViews (PartNumber As String, DrawingViewScale As Double, ViewsToPlace As String, AssemblyDrawing As Boolean, ByRef oBaseView As DrawingView, ByRef oView2 As DrawingView, ByRef oView3 As DrawingView, ByRef oView4 As SectionDrawingView)
  'RDS dims:
  Dim oDrawDoc As DrawingDocument
  Dim oPartDoc As Document
  Dim oSheet As Sheet
  Dim oTG As TransientGeometry
  Dim oPoint1 As Point2d
  Dim oPoint2 As Point2d
  Dim oPoint3 As Point2d
  Dim oPonit4 As Point2d
    'RDS dims in mm
    Dim sheetheight As Integer = 297    'sheet size A3
    Dim sheetwidth As Integer = 420      'sheet size A3
    Dim tableheight As Integer = 51        'type A
    Dim tablewidth As Integer = 160          'type A
    Dim borderoffset  As Integer = 10    'rounded up
    Dim viewdis  As Integer =10      'selective
    Dim baseviewheight As Integer = Height
    Dim baseviewwidth As Integer = Length
    Dim fitspaceheight As Integer = sheetheight -tableheight - (2*borderoffset)-(3*viewdis)
    Dim fitspacewidth As Integer = sheetwidth- (2*borderoffset)-(2*viesdis)-50
    Dim Hscale As Double = Height/fitspaceheight
    Dim Wscale As Double = Length/fitspacewidth
    Dim scale As Double 
      If Wscale> Hscale Then
      scale=Wscale
      Else If Hscale>Wscale Then
      scale=Hscale
      Else If Hscale=Wscale Then
      scale=Hscale
      End If
    Dim Xfactor As Double
    Dim Yfactor As Double 
    Dim Yfactortop As Double
    Dim Xfactorright As Double
    Dim Yfactorsection As Double
    Xfactor =((Length/(scale*2))+borderoffset+viewdis)/10
    Yfactor=(sheetheight-(Height/(scale*2))-viewdis-borderofset-borderoffset)/10
    Yfactortop= Yfactor-(Height/(scale*20))-(viewdis/10)
    Xfactorright=Xfactor+(Length/(scale*20))+(viewdis/10)
    Yfactorsection=(sheetheight-viewdis-borderofset)/10
    'RDS ends dim%
    
  
  'RDS places base view and other based on the file type assembly/part:
  If AssemblyDrawing = True Then
    oPartDoc = ThisDoc.Document
    oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2016\Templates\Standard_RDS.idw", True)
  Else If AssemblyDrawing = False 
    oPartDocPath = ThisDoc.Path & "\" & PartNumber & ".ipt"
    oPartDoc = ThisApplication.Documents.Open(oPartDocPath, False)
    oDrawDoc = ThisApplication.ActiveDocument 
  End If
  
  
  oSheet = oDrawDoc.Sheets.Item(1)
  oTG = ThisApplication.TransientGeometry
  
  
  oPoint1 = oTG.CreatePoint2d(Xfactor,Yfactor)
  oPoint2 = oTG.CreatePoint2d(Xfactor, Yfactortop)
  oPoint3 = oTG.CreatePoint2d(Xfactorright, Yfactor)
  oPoint4 = oTG.CreatePoint2d(Xfactor, Yfactorsection)
  
  'RDS Creates the Base View:      kHiddenLineRemovedDrawingViewStyle               kHiddenLineDrawingViewStyle    
  oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "Default")
  
  
  
  'RDS places other views:
  If ViewsToPlace = "Top" Then
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Right" 
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Project"
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Top_Right"
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
    oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Top_Project"
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineDrawingViewStyle, DrawingViewScale)
    oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Right_Project"

oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
    oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
    
  Else If ViewsToPlace = "Top_Right_Project"
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineDrawingViewStyle, DrawingViewScale)
    oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
    oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
  Else If ViewsToPlace="Top_Section"
    oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
    'RDS dims a line to cut the section
      Dim oDrawingSketch As DrawingSketch
      oDrawingSketch = oSheet.Sketches.Add
        
      oDrawingSketch.Edit
      Dim oSketchLine As SketchLine
      oSketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPoint2,oPoint4)
      oDrawingSketch.ExitEdit
      'RDS places section view
      'Dim oView3 As SectionDrawingView
      
      'at Inventor.DrawingViews.AddSectionView(DrawingView ParentView, DrawingSketch SectionLineSketch, Point2d Position, DrawingViewStyleEnum ViewStyle, Object Scale, Boolean ShowLabel, String Name, Boolean Reserved, Boolean FullDepth, Object SectionDepth)
         oView4 = oSheet.DrawingViews.AddSectionView(oBaseView,oDrawingSketch, oPoint3, kHiddenLineRemovedDrawingViewStyle,DrawingViewScale)
      
      'oDrawingSketch.Visible = False
      'RDS ends section job
  
  Else If ViewsToPlace = "None" Then
  'Only Place Base View, therefore do nothing
  End If
  
  
  
  Return oDrawDoc

End Function

'RDS dims new function
Function Structureview (STS As Boolean)
If STS=True Then
  For i=1 To row
  Component.IsActive("Facade-Row"&i) = False
  Component.IsActive("MetalFrame-Glass-Row"&i) = False
  Component.IsActive("MetalFrame-MDF-Row"&i) = False
  Component.IsActive("Sticker"&i) = False
  Component.IsActive("Top-Facade") = False
  Component.IsActive("Right Facade:2") = False
  Component.IsActive("Right Facade:1") = False
  Component.IsActive("Left Facade:2") = False
  Component.IsActive("Left Facade:1") = False

  Next

Else If STS=False Then
  'RDS asks user if he/she is done with structure
'  askagain:
'  structuredoneq=MessageBox.Show(" Are you Done with Structure? note that you would not do anything else while working on structure(RDS)  ", "Sajiran-Beta Partitioning System",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'    If structuredoneq=vbYes Then
    iLogicVb.RunRule("Beta Partitioning System")
'    Else If structuredoneq=vbNo Then
'    'RDS return
'    Goto askagain
'    End If
End If


End Function

 
'RDS ends rule

and errors i get is like this in error message tab:

 

 

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

and so in another one:

 

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DrawingViews.AddSectionView(DrawingView ParentView, DrawingSketch SectionLineSketch, Point2d Position, DrawingViewStyleEnum ViewStyle, Object Scale, Boolean ShowLabel, String Name, Boolean Reserved, Boolean FullDepth, Object SectionDepth)
   at LmiRuleScript.CreateDrawing_PlaceViews(String PartNumber, Double DrawingViewScale, String ViewsToPlace, Boolean AssemblyDrawing, DrawingView& oBaseView, DrawingView& oView2, DrawingView& oView3, SectionDrawingView& oView4)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

do you have any idea what is is wanna tell????

 

 

0 Likes
Accepted solutions (1)
2,058 Views
5 Replies
Replies (5)
Message 2 of 6

Owner2229
Advisor
Advisor

Hi, IMO the issue is that you're creating a sketch on the sheet instead of the view (like you would do manually).

I don't have the time right now for a full rework, but I've simplyfied your code a bit.

Also, I've removed most of your comments, so you have to dig throught it and learn. Good luck.

Pay special attention to the last line of my signature.

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports Inventor.DrawingViewTypeEnum
Imports Inventor.PointIntentEnum
Imports Inventor.DimensionTypeEnum
Imports Inventor.DrawingCurveSegmentEnum
Imports Inventor.DrawingCurveEnum
Imports Inventor.CurveTypeEnum

Sub Main()
	Dim AskCreateDrawing As DialogResult = MessageBox.Show("If you would like to create a  STRUCTURE drawing from this view, please hit YES and then fill up comming filds (RDS)  ", "Sajiran-Beta Partitioning System",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	If AskCreateDrawing <> vbYes Then Exit Sub
	iProperties.Value("Project", "Project") = InputBox("Enter Project Name:", "Sajiran-Beta Partitioning System", "Sajiran")
	iProperties.Value("project", "Stock Number") = InputBox("Enter Project Code:", "Sajiran-Beta Partitioning System", "1234")
	iProperties.Value("Status", "Status") = InputBox("Enter View Name:", "Sajiran-Beta Partitioning System", "View 1")
	Structureview (True)
	Dim DrawingViewScale As Double = 1 / scale
	Dim AssemblyDocName As String = ThisDoc.FileName(False) 'without extension
	Dim Assem_DrawingDoc As DrawingDocument = CreateDrawing_PlaceViews (AssemblyDocName, DrawingViewScale, "Top_Section", True, oBaseView, oRightSideView, oProjectView, oView4)
	Dim oPartPath As String = ThisDoc.Path
	Dim oPartPathLength As Integer = Len(oPartPath)
	Dim oDrawingPath As String = Left(oPartPath, oPartPathLength - 7)
	Dim oDrawingDoc As String = oDrawingPath & "\" & AssemblyDocName & ".idw"
	Assem_DrawingDoc.SaveAs(oDrawingDoc, False)
	Assem_DrawingDoc.Close(True)
	Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingDoc, True)	
    Structureview (False)
End Sub

Private Function GetScale() As Integer
	If Wscale > Hscale Then
		Return Wscale
	Else
		Return Hscale
	End If
End Function

Private sheetheight As Integer = 297	'sheet size A3
Private sheetwidth As Integer = 420	'sheet size A3
Private tableheight As Integer = 51	'type A
Private tablewidth As Integer = 160	'type A
Private borderoffset  As Integer = 10	'rounded up
Private viewdis  As Integer = 10	'selective
Private baseviewheight As Integer = Height
Private baseviewwidth As Integer = Length
Private fitspaceheight As Integer = sheetheight -tableheight - (2*borderoffset)-(3*viewdis)
Private fitspacewidth As Integer = sheetwidth- (2*borderoffset)-(2*viesdis)-50
Private Hscale As Double = Height/fitspaceheight
Private Wscale As Double = Length/fitspacewidth
Private scale As Double = GetScale()

Function CreateDrawing_PlaceViews (PartNumber As String, DrawingViewScale As Double, ViewsToPlace As String, AssemblyDrawing As Boolean, ByRef oBaseView As DrawingView, ByRef oView2 As DrawingView, ByRef oView3 As DrawingView, ByRef oView4 As SectionDrawingView) As DrawingDocument
	Dim Xfactor As Double = ((Length/(scale*2))+borderoffset+viewdis)/10
	Dim Yfactor As Double = (sheetheight-(Height/(scale*2))-viewdis-borderofset-borderoffset)/10
	Dim Yfactortop As Double = Yfactor-(Height/(scale*20))-(viewdis/10)
	Dim Xfactorright As Double = Xfactor+(Length/(scale*20))+(viewdis/10)
	Dim Yfactorsection As Double = (sheetheight-viewdis-borderofset)/10
	Dim oDrawDoc As DrawingDocument
	Dim oPartDoc As Document
	If AssemblyDrawing Then
		oPartDoc = ThisDoc.Document
		oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2016\Templates\Standard_RDS.idw", True)
	Else
		Dim oPartDocPath As String = ThisDoc.Path & "\" & PartNumber & ".ipt"
		oPartDoc = ThisApplication.Documents.Open(oPartDocPath, False)
		oDrawDoc = ThisApplication.ActiveDocument 
	End If
	Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oPoint1 As Point2d = oTG.CreatePoint2d(Xfactor,Yfactor)
	Dim oPoint2 As Point2d = oTG.CreatePoint2d(Xfactor, Yfactortop)
	Dim oPoint3 As Point2d = oTG.CreatePoint2d(Xfactorright, Yfactor)
	Dim oPoint4 As Point2d = oTG.CreatePoint2d(Xfactor, Yfactorsection)
	
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "Default")
	
	Select Case ViewsToPlace
	Case "Top":	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
	Case "Right":	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
	Case "Project":	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	Case "Top_Right"
		oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
		oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
	Case "Top_Project"
		oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineDrawingViewStyle, DrawingViewScale)
		oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	Case "Right_Project"
		oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
		oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	Case "Top_Right_Project"
		oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineDrawingViewStyle, DrawingViewScale)
		oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, DrawingViewScale)
		oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, DrawingViewScale)
	Case "Top_Section"
		oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
		Dim oDrawingSketch As DrawingSketch = oBaseView.Sketches.Add
		oDrawingSketch.Edit
		Dim oSketchLine As SketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPoint2, oPoint4)
		oDrawingSketch.ExitEdit
		oView4 = oSheet.DrawingViews.AddSectionView(oBaseView, oDrawingSketch, oPoint3, kHiddenLineRemovedDrawingViewStyle, DrawingViewScale)
	Case "None":	'Only Place Base View, therefore do nothing
	End Select
	Return oDrawDoc
End Function

Sub Structureview (STS As Boolean)
	If STS Then
		For i = 1 To row
			Component.IsActive("Facade-Row" & i) = False
			Component.IsActive("MetalFrame-Glass-Row" & i) = False
			Component.IsActive("MetalFrame-MDF-Row" & i) = False
			Component.IsActive("Sticker" & i) = False
		Next
		Component.IsActive("Top-Facade") = False
		Component.IsActive("Right Facade:2") = False
		Component.IsActive("Right Facade:1") = False
		Component.IsActive("Left Facade:2") = False
		Component.IsActive("Left Facade:1") = False
	Else
		iLogicVb.RunRule("Beta Partitioning System")
	End If
End Sub

 

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
Message 3 of 6

Anonymous
Not applicable

thank you a lot Mike,

there were several good points in the code to learn.thank you. 

also, i am now thinking about that psychopath Smiley Wink

 

but about the code, this did not give me even the base & top view, just an error message came up and sheet disappeared.

 

i'm getting this error:

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DrawingViews.AddProjectedView(DrawingView ParentView, Point2d Position, DrawingViewStyleEnum ViewStyle, Object Scale)
   at LmiRuleScript.CreateDrawing_PlaceViews(String PartNumber, Double DrawingViewScale, String ViewsToPlace, Boolean AssemblyDrawing, DrawingView& oBaseView, DrawingView& oView2, DrawingView& oView3, SectionDrawingView& oView4)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 4 of 6

Owner2229
Advisor
Advisor

That's strange. I've just tested it and it worked. It added all 3 views as expected (even the section view).

 

The only thing I had to add was this below, since as you said in your original post, you're taking it from parameters:

 

Private Height As Integer = 100
Private Length As Integer = 100

And you've had there one typo "viesdis" instead of "viewdis" in the "fitspacewidth" variable.

Anyway, please test this simple code below first, we're gonna rebuild your rule.

All it should do is add a new drawing with the views.

Also, no more imports. Go ahead and test all the view groups.

I'm still not yet done with it. I'll definitely split the functions for adding the new drawing and adding the views, so the second doesn't have to return the document, but rather just work with it.

 

Sub Main()
	If Wscale > Hscale Then Scale = Wscale Else Scale = Hscale
	DWScale = 1 / Scale
	Dim AsmDocName As String = ThisDoc.FileName(False) 'Without extension
	Dim AsmDoc As DrawingDocument = CreateDrawing_PlaceViews (AssemblyDocName, "Top_Section", True)
End Sub

Private Height As Integer = 100
Private Length As Integer = 100

Private sheetheight As Integer = 297	'sheet size A3
Private sheetwidth As Integer = 420	'sheet size A3
Private tableheight As Integer = 51	'type A
Private tablewidth As Integer = 160	'type A
Private borderoffset  As Integer = 10	'rounded up
Private viewdis As Integer = 10		'selective
Private baseviewheight As Integer = Height
Private baseviewwidth As Integer = Length
Private fitspaceheight As Integer = sheetheight - tableheight - (2 * borderoffset) - (3 * viewdis)
Private fitspacewidth As Integer = sheetwidth - (2 * borderoffset) - (2 * viewdis) - 50
Private Hscale As Double = Height / fitspaceheight
Private Wscale As Double = Length / fitspacewidth
Private Scale As Double
Private DWScale As Double
Private oHidden As DrawingViewStyleEnum = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
Private oHiddenRemoved As DrawingViewStyleEnum = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle

Function CreateDrawing_PlaceViews (PartNumber As String, ViewsToPlace As String, AssemblyDrawing As Boolean) As DrawingDocument
	Dim Xfactor As Double = ((Length / (scale * 2)) + borderoffset + viewdis) / 10
	Dim Yfactor As Double = (sheetheight - (Height / (scale * 2)) - viewdis - borderofset - borderoffset) / 10
	Dim Yfactortop As Double = Yfactor - (Height / (scale * 20)) - (viewdis / 10)
	Dim Xfactorright As Double = Xfactor + (Length / (scale * 20)) + (viewdis / 10)
	Dim Yfactorsection As Double = (sheetheight - viewdis - borderofset) / 10
	Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2016\Templates\Standard_RDS.idw", True)
	Dim oPartDoc As Document = ThisDoc.Document
	
	Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oPoint1 As Point2d = oTG.CreatePoint2d(Xfactor, Yfactor)
	Dim oPoint2 As Point2d = oTG.CreatePoint2d(Xfactor, Yfactortop)
	Dim oPoint3 As Point2d = oTG.CreatePoint2d(Xfactorright, Yfactor)
	Dim oPoint4 As Point2d = oTG.CreatePoint2d(Xfactor, Yfactorsection)
	
	Dim oDW As DrawingViews = oSheet.DrawingViews
	Dim oBaseOri As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kFrontViewOrientation
	Dim oBaseView As DrawingView = oDW.AddBaseView(oPartDoc, oPoint1, DWScale, oBaseOri, oHiddenRemoved, "Default")
	
	Select Case ViewsToPlace
	Case "Top":			AddViews(oDW, oBaseView, {oPoint2}, oHiddenRemoved)
	Case "Right":			AddViews(oDW, oBaseView, {oPoint3}, oHidden)
	Case "Project":			AddViews(oDW, oBaseView, {oPoint4}, oHidden)
	Case "Top_Right":		AddViews(oDW, oBaseView, {oPoint2, oPoint3}, oHiddenRemoved)
	Case "Top_Project":		AddViews(oDW, oBaseView, {oPoint2, oPoint4}, oHidden)
	Case "Right_Project":		AddViews(oDW, oBaseView, {oPoint3, oPoint4}, oHidden)
	Case "Top_Right_Project":	AddViews(oDW, oBaseView, {oPoint2, oPoint3, oPoint4}, oHidden)
	Case "Top_Section"
		AddViews(oDW, oBaseView, {oPoint2}, oHiddenRemoved)
		Dim oDrawingSketch As DrawingSketch = oBaseView.Sketches.Add
		oDrawingSketch.Edit
		Dim oSketchLine As SketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPoint2, oPoint4)
		oDrawingSketch.ExitEdit
		Dim oView As SectionDrawingView = oDW.AddSectionView(oBaseView, oDrawingSketch, oPoint3, oHiddenRemoved, DWScale)
	Case "None":	'Only Place Base View, therefore do nothing
	End Select
	Return oDrawDoc
End Function

Private Sub AddViews(oDW As DrawingViews, oBaseView As DrawingView, oPoints As Point2d(), DWStyle As DrawingViewStyleEnum)
	For Each oPoint As Point2d In oPoints
		Dim oView As DrawingView = oDW.AddProjectedView(oBaseView, oPoint, DWStyle, DWScale)
	Next
End Sub

 

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
Message 5 of 6

Anonymous
Not applicable
Accepted solution

it was also strange for me, I checked the code several times, and everything was fine, 

I have also corrected the typo "viesdis"  , also I have tried to get the just base view  and/or base view + top view with the code, but I was just getting the same error message. 

 

but fortunately today,  referring to your first advice  to sketch a line in view instead of the sheet, I have changed  a line in my own code:

"oSheet.Sketches.Add" changed into => "oBaseView.Sketches.Add"

 

and it worked fine. Smiley Very Happy

 

that was also interesting for me that coordinate system also changed.  so I defined 2 new points to control the section line in base view. and everything is fine right now. 

 

thank you for your helpful advice 

0 Likes
Message 6 of 6

Owner2229
Advisor
Advisor

The coordinate system changed to the boundaries of the base view, so [0,0] is no longer the top left of the sheet, but rather top left of the base view.

If you want me to finish the rework, then just test the last code and let me know if it worked properly.

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