Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

View.Height shows as int in Visual Studio?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
TCARPENTER21
251 Views, 3 Replies

View.Height shows as int in Visual Studio?

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.

3 REPLIES 3
Message 2 of 4
WCrihfield
in reply to: TCARPENTER21

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)

Message 3 of 4


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

Message 4 of 4
jjstr8
in reply to: TCARPENTER21

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report