Convert VB.net Code to c Sharp

Convert VB.net Code to c Sharp

navbor
Enthusiast Enthusiast
1,051 Views
1 Reply
Message 1 of 2

Convert VB.net Code to c Sharp

navbor
Enthusiast
Enthusiast

Hello There,

 

I am busy converting one of my AddIns to C# (from VB.net). I am relatively new to C#. Below are two excerpts of code, the VB code works fine, but the C# code breaks down. Any advice / help would be sincerely appreciated.

 

VB.net

 

Dim Radius, viewscale As Double
Dim oTG As TransientGeometry
Dim oCenterPoint As Point2d

oSelectSet = g_inventorApplication.ActiveDocument.SelectSet
oTG = g_inventorApplication.TransientGeometry

For Each oSelectedObject In oSelectSet
If TypeName(oSelectedObject) = "DrawingCurveSegment" Then
oDrawingCurveSegment = oSelectedObject
If oDrawingCurveSegment.GeometryType = Curve2dTypeEnum.kCircleCurve2d Then
Radius = oDrawingCurveSegment.Geometry.Radius
viewscale = oDrawingCurveSegment.Parent.Parent.Scale
oCenterPoint = oTG.CreatePoint2d(oDrawingCurveSegment.Geometry.Center.X, oDrawingCurveSegment.Geometry.Center.Y)

 

c#

double radius,viewscale;
Point2d oCenterPoint;

foreach (Object oSelectedObject in oSelectSet)
{
if (Information.TypeName(oSelectedObject) == "DrawingCurveSegment")
{
oDrawingCurveSegment = (DrawingCurveSegment)oSelectedObject;
if (oDrawingCurveSegment.GeometryType == Curve2dTypeEnum.kCircleCurve2d)
{

radius = oDrawingCurveSegment.Geometry.Radius;
viewscale = oDrawingCurveSegment.Parent.Parent.Scale;
oCenterPoint = oTG.CreatePoint2d(oDrawingCurveSegment.Geometry.Center.X, oDrawingCurveSegment.Geometry.Center.Y);

 

Error message/s:

 

Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'Radius' and no extension method 'Radius' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) DowelSymbolCS C:\Users\Rob\Documents\Visual Studio 2015\Projects\DowelSymbolCS\DowelSymbolCS\DowelHoleCommand.cs 119 Active

 

Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'Center' and no extension method 'Center' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) DowelSymbolCS C:\Users\Rob\Documents\Visual Studio 2015\Projects\DowelSymbolCS\DowelSymbolCS\DowelHoleCommand.cs 121 Active

 

Thanks very much

 

 

 

 

 

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Accepted solutions (1)
1,052 Views
1 Reply
Reply (1)
Message 2 of 2

navbor
Enthusiast
Enthusiast
Accepted solution

Problem Solved,

 

I had to add a few more steps and type casts. I am not sure if this is the best solution (experts comments welcome), but it does, so I am going to call it solved:

 

double radius,viewscale;
Point2d oCenterPoint;
Circle2d ocircle;
foreach (Object oSelectedObject in oSelectSet)
{
if (Information.TypeName(oSelectedObject) == "DrawingCurveSegment")
{
oDrawingCurveSegment = (DrawingCurveSegment)oSelectedObject;
if (oDrawingCurveSegment.GeometryType == Curve2dTypeEnum.kCircleCurve2d)
{
ocircle = (Circle2d)oDrawingCurveSegment.Geometry;
radius = ocircle.Radius;
viewscale = oDrawingCurveSegment.Parent.Parent.Scale;
oCenterPoint = oTG.CreatePoint2d(ocircle.Center.X, ocircle.Center.Y);

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes