So, I'm in the process of converting my most used VBA macros to a C# add-in. I'm generating CS0266 error when trying to set View.Height. For some reason, Visual Studio thinks View.Height should be an int., but the documentation shows it as being a long (which would make more sense).
Here's the error:
Here's my code - am I doing something wrong?
DrawingDocument oDrawDoc = (DrawingDocument)Globals.InvApp.ActiveDocument;
string sBaseFName = oDrawDoc.DisplayName;
sBaseFName = System.IO.Path.GetFileNameWithoutExtension(sBaseFName);
try
{
// Set the active sheet and view
DrawingDocument oDoc =
(DrawingDocument)Globals.InvApp.ActiveDocument;
Sheet oSheet = oDoc.ActiveSheet;
Inventor.View oView = Globals.InvApp.ActiveView;
double dAspectRatio = oSheet.Height / oSheet.Width;
// Adjust the aspect ratio of the view to match that of the sheet
oView.Height = oView.Width * dAspectRatio;
Camera oCamera = oView.Camera;
This is Inventor2023 and Visual Studio 2022 if any of that matters.
Thanks for any suggestions.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @TCARPENTER21. I assume you are referring to a regular Inventor.View type object and its Height property, and not an Inventor.DrawingView type object and its Height property, based on the one screenshot. Unfortunately, most of the online help documentation was created a long time ago, and they had using VBA in mind at the time. That is why you often see them refer to Variant instead of Object in a lot of places. This is also true for the Long (or Int64) term. They specify that a lot in the online help area, but when working within an iLogic rule, the Integer (or Int32) data type is generally what is always expected. There may be a few exceptions though.
Edit: Below is a screen capture from an iLogic rule in Inventor 2024.
Wesley Crihfield
(Not an Autodesk Employee)
@TCARPENTER21 wrote:For some reason, Visual Studio thinks View.Height should be an int., but the documentation shows it as being a long (which would make more sense).
IV say Long, VS say Int and you made it a Double.
@TCARPENTER21 : In case it wasn't clear from @WCrihfield 's post, a VBA "Long" (from the API documentation) is a C# "int". Just use the Intellisense explicit cast suggestion: (int)(oView.Width * dAspectRatio)
Can't find what you're looking for? Ask the community or share your knowledge.