ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
PMPrashant Mohan24/05/2017

Hello Everyone,

I was trying to implement a Macro which selects a surface on a cube and draw rectangles on it using the CreateCenterRectangle method. The units i was using is Microns (code below). The code works, However, it is not drawing the center of rectangle at the right position. If you look at the code below the center is -1089.14 , 7993.52. However on actual rectangle it is way off (see the screenshot). I am not sure why is that happening or what could be done to correct it.

Any help or suggestions are welcome.

Code:

Dim vSkLines As Variant

Part.SketchManager.InsertSketch True

Set swSketchMgr = Part.SketchManager

swSketchMgr.AddToDB = True

'Setting units to micorns

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMICRON)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, 0, 5)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swMICRON)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearDecimalPlaces, 0, 5)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchInference, 0, False)

'Set swSketchSegment = swSketchMgr.CreateCircleByRadius(0, 0, 0, (2 / 1000000)) ' equialent to 2 microns

'Now looping through all points and drawing rectangles on the surface

'for now x = 150 microns and Y = 200 microns

swSketchMgr.AddToDB = True

  vSkLines = swSketchMgr.CreateCenterRectangle((-1089.14 / 1000000), (7993.52 / 1000000), 0, ((-1089.14 + 500) / 1000000), ((7993.52 + 500) / 1000000), 0)

Actual Rectangle screenshot:

2017-05-24_1544.png