DWG syntex

DWG syntex

Anonymous
Not applicable
481 Views
4 Replies
Message 1 of 5

DWG syntex

Anonymous
Not applicable

hi there is this correct syntex to create a dwg from scratch ?

 

SyntaxEditor Code Snippet

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum


Dim oDrawingDoc As DrawingDocument
Dim oPartDoc As PartDocument
Dim oSheet As Sheet
Dim oBaseView As DrawingView

'show dialog box asking the user are they sure they want to do this

DWGcreate = MsgBox("would you like to create a drawing?" & vbLf & vbLf & "this will create a Base,Top,ISO view then section the base view",vbYesNo,"Ilogic")

'if the user says yes then do the following...
If DWGCreate = vbYes Then

opartdoc = ThisDoc.Document
'go and grabe the drawing file template and open
oDrawingDoc = ThisApplication.Document.Add(DocumentTypeEnum.kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))

'Activate the drawing file
oDrawingDoc.Activate()
oSheet = oDrawingDoc.Sheets.Item(1)

'create a reference point to relate to the base view (x,y)

oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(7,10)

'place the base view at point 1
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1/6, kFrontViewOrientation, kHiddenLineDrawingViewStyle)

Dim otopview As DrawingView
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(7,23)
otopview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)

Dim oIsoView As DrawingView
oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(35,23)
oIsoview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, DrawingViewStyleEnum.kShadedDrawingViewStyle)

'create a front section view by defining a section line in th base view
Dim oSectionSketch As DrawingSketch
OsectionSketch = obaseview.Sketches.Add
oSectionSketch.Edit()

'Draw the section line
Dim oSectionLine As SketchLine

oSPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(0,-30)
oSPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(0,30)

oSectionLine = oSectionSketch.SketchLines.AddByTwoPoint(oSPoint1, oSPoint2)
oSectionSketch.ExitEdit()

Dim osectionview As SectionDrawingView
oSPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(35,23)
osectionview = oSheet.DrawingViews.AddSectionView(obaseview, oSectionSketch, oSPoint3, DrawingViewStyleEnum.kShadedDrawingViewStyle, 1/6, True, "A")

'retrieve my dimensions
dwgretrieve = MsgBox("would you like to bring through the dimensions" & vbLf & vbLf & "This will retrieve the dimesnions from views",vbYesNo, "Ilogic")
If dwgretrieve = vbYes Then

osheet.drawingdimensions.generaldimensions.retrieve(obaseview)

End If
End If




thanks.
0 Likes
482 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

Hi, your code was missing 3 things:

 

1. Proper nesting (it's easier to read this way, but doesn't affect functionality)

2. An "s" on Documents for ThisApplication.Documents....

3. An "s" on AddByTwoPoints for adding the section line.

 

Works fine otherwise.

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Sub Main()

	Dim oDrawingDoc As DrawingDocument
	Dim oPartDoc As PartDocument
	Dim oSheet As Sheet
	Dim oBaseView As DrawingView
	
	DWGcreate = MsgBox("Would you like to create a drawing?" & vbLf & vbLf & "this will create a Base,Top,ISO view then section the base view",vbYesNo,"Ilogic")
	
	If DWGCreate = vbYes Then
		
		opartdoc = ThisDoc.Document
		oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))
		
		oDrawingDoc.Activate()
		oSheet = oDrawingDoc.Sheets.Item(1)
				
		oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(7,10)
		
		oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1/6, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
		
		Dim otopview As DrawingView
		oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(7,23)
		otopview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
		
		Dim oIsoView As DrawingView
		oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(35,23)
		oIsoview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, DrawingViewStyleEnum.kShadedDrawingViewStyle)
		
		'create a front section view by defining a section line in th base view
		Dim oSectionSketch As DrawingSketch
		OsectionSketch = obaseview.Sketches.Add
		oSectionSketch.Edit()
		
		'Draw the section line
		Dim oSectionLine As SketchLine
		
		oSPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(0,-30)
		oSPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(0,30)
		
		oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oSPoint1, oSPoint2)
		oSectionSketch.ExitEdit()
		
		Dim osectionview As SectionDrawingView
		oSPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(35,23)
		osectionview = oSheet.DrawingViews.AddSectionView(obaseview, oSectionSketch, oSPoint3, DrawingViewStyleEnum.kShadedDrawingViewStyle, 1/6, True, "A")
		
		'retrieve my dimensions
		dwgretrieve = MsgBox("would you like to bring through the dimensions" & vbLf & vbLf & "This will retrieve the dimesnions from views",vbYesNo, "Ilogic")
		If dwgretrieve = vbYes Then
			osheet.drawingdimensions.generaldimensions.retrieve(obaseview)
		End If
	End If

End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for the help i have amended my syntex but i get this error ?

 

Error in rule: Create DWG, in document: ASS--ILOGIC FINAL.iam

Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Any ideas ?

 

thanks.

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor

Don't try running it in an assembly as it's not coded for it...

 

 

Or change the 

 

Dim oPartDoc As PartDocument

line to use the generic version;

 

Dim oPartDoc As Document

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 5

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Check this out:

 

  1. Create a *.txt file new with Right Mouse Button (RMB) in the Explorer (NewDoc.txt)
  2. rename it to NewDoc.dwg
  3. open this NewDoc.dwg (with RMB openwith "Inventor")
  4. and ready

this works fine.

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes