View.Height shows as int in Visual Studio?

TCARPENTER21
Enthusiast
Enthusiast

View.Height shows as int in Visual Studio?

TCARPENTER21
Enthusiast
Enthusiast

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).  

 

TCARPENTER21_0-1688734024463.png

 

Here's the error:

 

TCARPENTER21_1-1688734463566.png

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.

0 Likes
Reply
Accepted solutions (1)
333 Views
3 Replies
Replies (3)

WCrihfield
Mentor
Mentor
Accepted 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.

WCrihfield_0-1688736411242.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Frederick_Law
Mentor
Mentor

@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).  

 

TCARPENTER21_1-1688734463566.png

 


IV say Long, VS say Int and you made it a Double.

0 Likes

jjstr8
Collaborator
Collaborator

@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)

0 Likes