Hi,
Inventor 2024
API ViusalStudio 2022
I try to write a script in C# to Create a DrawingView, but i got a Error.
This is a Sample:
Inventor.DrawingDocument oDrawingDoc = (DrawingDocument)Globals.g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,null,true);
oDrawingDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits;
Inventor.Document oDoc = Globals.g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,"",true);
oDrawingDoc = (DrawingDocument)oDoc;
Inventor.Sheet oSheet = oDrawingDoc.Sheets.Add(DrawingSheetSizeEnum.kA0DrawingSheetSize);
Point2d oPointDrawingStart = oTG.CreatePoint2d(50, 50);
double oScale = 1;
DrawingView oViewSheet = oSheet.DrawingViews.AddBaseView((Inventor._Document)oPartBridge_Doc, oPointDrawingStart, oScale,ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle);
I get a Error with DrawingView oViewSheet " Unknow Error"
In VB.NET is working
Dim oDrawingDoc As DrawingDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,, SystemOfMeasureEnum.kMetricSystemOfMeasure)
Dim oSheet As Sheet = oDrawingDoc.Sheets.Add(DrawingSheetSizeEnum.kA0DrawingSheetSize)
Dim oDrawingPointStart As Point2d = oTG.CreatePoint2d(60, 50)
Dim oScale As Double = 1
Dim oViewSheet As DrawingView = oSheet.DrawingViews.AddBaseView(oPart_Unfold_Doc, oDrawingPointStart, oScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
Dim oUnitDrawing As UnitsOfMeasure = oDrawingDoc.UnitsOfMeasure
oDrawingDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits
oDrawingDoc.StylesManager.ActiveStandardStyle = oDrawingDoc.StylesManager.StandardStyles("Standardnorm (DIN)")
What i need to do it in C#
Also, i dont know how to set the:
SystemOfMeasureEnum.kMetricSystemOfMeasure
in C# ??
Thanks for Any Suggestion
Hi @florian_wenzel. First, I am wandering why you are creating 2 new drawing documents with two different variables, then setting the value of the second one as the value of the first one in your C# code. You set the measurement system of the first one, then create another document, then overwrite the first one with the second one, effectively eliminating that setting. I'm guessing that it might be possible that the wrong referenced document (of the two) may be the 'active' one at the time you are trying to add that DrawingView, but that is just a guess. I would think that adding a new sheet to the drawing would have 'activated' the correct one, if that was a problem though.
Next, I do not know where you are getting that 'SystemOfMeasureEnum.kMetricSystemOfMeasure', or why you are trying to use it there. The Documents.Add() method does not allow for that type of input. Another thing that seems possibly out of place is the use of (Inventor._Document) in your C# code's DrawingViews.AddBaseView() method. As far as I can tell, it is just expecting a normal Document type object, which would definately contain something native to Inventor. Is the model in that case a directly imported model file, like a STEP file?
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.