What tells this

What tells this

jletcher
Advisor Advisor
777 Views
15 Replies
Message 1 of 16

What tells this

jletcher
Advisor
Advisor

Ok trying to understand this code but for the life of me I cannot find how it is telling it to be  cm instead of inches. Trying to make a sheet metal part with ilogic so I got this from the API sample and got it to work with ilogic but I cannot figure where the cm is to change to inch.

 

' Create a new sheet metal document, using the default sheet metal template.
    Dim oSheetMetalDoc As PartDocument
     oSheetMetalDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject, , , "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"))

    ' Set a reference to the component definition.
    Dim oCompDef As SheetMetalComponentDefinition
     oCompDef = oSheetMetalDoc.ComponentDefinition

    ' Set a reference to the sheet metal features collection.
    Dim oSheetMetalFeatures As SheetMetalFeatures
     oSheetMetalFeatures = oCompDef.Features

    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
     oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))

    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
     oTransGeom = ThisApplication.TransientGeometry

    ' Draw a 4cm x 3cm rectangle with the corner at (0,0)
    Call oSketch.SketchLines.AddAsTwoPointRectangle( _
                                oTransGeom.CreatePoint2d(0, 0), _
                                oTransGeom.CreatePoint2d(4, 3))

    ' Create a profile.
    Dim oProfile As Profile
     oProfile = oSketch.Profiles.AddForSolid

    Dim oFaceFeatureDefinition As FaceFeatureDefinition
     oFaceFeatureDefinition = oSheetMetalFeatures.FaceFeatures.CreateFaceFeatureDefinition(oProfile)

    ' Create a face feature.
    Dim oFaceFeature As FaceFeature
     oFaceFeature = oSheetMetalFeatures.FaceFeatures.Add(oFaceFeatureDefinition)

    ' Get the top face for creating the flange.
    ' We'll assume that the 6th face is the top face.
    Dim oFrontFace As Face
     oFrontFace = oFaceFeature.Faces.Item(6)

    ' Collect up all edges of the face
    Dim oEdgeCollection As EdgeCollection
     oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

    Dim oEdge As Edge
    For Each oEdge In oFrontFace.Edges
        Call oEdgeCollection.Add(oEdge)
    Next

    Dim oFlangeDefinition As FlangeDefinition
     oFlangeDefinition = oSheetMetalFeatures.FlangeFeatures.CreateFlangeDefinition(oEdgeCollection, 3.14159 / 2, "2 in")

    ' Set the bend radius value
    oFlangeDefinition.BendRadius = oCompDef.BendRadius.Value * 2

    ' Create a flange feature
    Dim oFlangeFeature As FlangeFeature
    oFlangeFeature = oSheetMetalFeatures.FlangeFeatures.Add(oFlangeDefinition)

 Many thanks..

0 Likes
778 Views
15 Replies
Replies (15)
Message 2 of 16

jdkriek
Advisor
Advisor

It's in the file generation, I tried it out and it did not use my default sheetmetal template, but it still generated a part, lol

 

So I just specifiy the template I want and it works fine.

 

Make sure the units in the template you specify are set to inches

 

sTemplate = "I:\PathToYourTemplate\SheetMetal.ipt"
Dim oSheetMetalDoc As PartDocument
oSheetMetalDoc = ThisApplication.Documents.Add(kPartDocumentObject, sTemplate, True)
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 3 of 16

jdkriek
Advisor
Advisor

Of course you can always just set it back to inch or mm with this 😉

 

doc = ThisDoc.Document

'Use this for IN
doc.unitsofmeasure.lengthunits = 11272

'Use this for MM
doc.unitsofmeasure.lengthunits = 11269

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 4 of 16

jletcher
Advisor
Advisor

Ok thanks I will give it a shot..

0 Likes
Message 5 of 16

jletcher
Advisor
Advisor

Ok i tried but not working. I changed to thisdoc so it don't make a new part and I am in inches but still comes out cm.

 

doc = ThisDoc.Document
oSheetMetalDoc =ThisDoc.Document
'Use this for IN
Doc.unitsofmeasure.lengthunits = 11272


    ' Set a reference to the component definition.
    Dim oCompDef As SheetMetalComponentDefinition
     oCompDef = oSheetMetalDoc.ComponentDefinition

    ' Set a reference to the sheet metal features collection.
    Dim oSheetMetalFeatures As SheetMetalFeatures
     oSheetMetalFeatures = oCompDef.Features

    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
     oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))

    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
     oTransGeom = ThisApplication.TransientGeometry

    ' Draw a 4cm x 3cm rectangle with the corner at (0,0)
	oSketch.SketchLines.AddAsTwoPointRectangle( _ 
                                oTransGeom.CreatePoint2d(0, 0), _
                                oTransGeom.CreatePoint2d(4, 3))

    ' Create a profile.
    Dim oProfile As Profile
     oProfile = oSketch.Profiles.AddForSolid

    Dim oFaceFeatureDefinition As FaceFeatureDefinition
     oFaceFeatureDefinition = oSheetMetalFeatures.FaceFeatures.CreateFaceFeatureDefinition(oProfile)

    ' Create a face feature.
    Dim oFaceFeature As FaceFeature
     oFaceFeature = oSheetMetalFeatures.FaceFeatures.Add(oFaceFeatureDefinition)

    ' Get the top face for creating the flange.
    ' We'll assume that the 6th face is the top face.
    Dim oFrontFace As Face
     oFrontFace = oFaceFeature.Faces.Item(6)

    ' Collect up all edges of the face
    Dim oEdgeCollection As EdgeCollection
     oEdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

    Dim oEdge As Edge
    For Each oEdge In oFrontFace.Edges
        Call oEdgeCollection.Add(oEdge)
    Next

    Dim oFlangeDefinition As FlangeDefinition
     oFlangeDefinition = oSheetMetalFeatures.FlangeFeatures.CreateFlangeDefinition(oEdgeCollection, 3.14159 / 2, "2 in")

    ' Set the bend radius value
    oFlangeDefinition.BendRadius = oCompDef.BendRadius.Value * 2

    ' Create a flange feature
    Dim oFlangeFeature As FlangeFeature
    oFlangeFeature = oSheetMetalFeatures.FlangeFeatures.Add(oFlangeDefinition)

 

 

0 Likes
Message 6 of 16

jdkriek
Advisor
Advisor

I wonder if this has anything to do with it?

http://forums.autodesk.com/t5/Autodesk-Inventor/Inventor-changes-to-cm-instead-of-mm/m-p/3251852#M42...

 

Honestly, I don't have this problem, so I can't troubleshoot it.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 7 of 16

jletcher
Advisor
Advisor

So you are saying when you run this code it does it in inches?

 

I never renamed my template files so that other issue i don't think is my issue.

0 Likes
Message 8 of 16

jdkriek
Advisor
Advisor

Yes, when I run the code it's in inches.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 9 of 16

jletcher
Advisor
Advisor

when you ran this did you go into the sketch and dimension the the rectangle? I have tried everything and still in cm no matter what I do I can't get it to be inches.....

0 Likes
Message 10 of 16

jdkriek
Advisor
Advisor

That's exactly how I tested it.

 

Really bizarre.

 

Have you cleared out your session, closed Inventor, restarted?

 

I can't imagine what is causing you to be stuck in cm.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 11 of 16

jletcher
Advisor
Advisor

Yeah even removed all other templates from the computer..

0 Likes
Message 12 of 16

jletcher
Advisor
Advisor

How about it Autodesk you going to step in so I can finish this before release 2020..

0 Likes
Message 13 of 16

jletcher
Advisor
Advisor

It is funny how Autodesk jumbs on some and leaves others hanging.

 

Be nice to make my part....................

0 Likes
Message 14 of 16

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

It seems there are some questions in this thread. About this one "....use my default sheetmetal template, but it still generated a part":  to create a sheet metal file, you need to specify subtype, e.g.

 

Dim oSheetMetalDoc As PartDocument

oSheetMetalDoc = _InvApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _

    _InvApplication.FileManager.GetTemplateFile(_

  DocumentTypeEnum.kPartDocumentObject, _

  SystemOfMeasureEnum.kDefaultSystemOfMeasure, _

  DraftingStandardEnum.kDefault_DraftingStandard, _

  "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"))

0 Likes
Message 15 of 16

jletcher
Advisor
Advisor

Sorry but thats not my issue in my code it does have sheet metal to be used. The issue is with the code posted it makes it in cm not inches but my template is in inches.

 

 

My question is what in the code tells it to change my template to be cm?

0 Likes
Message 16 of 16

Anonymous
Not applicable
Hi jletcher,

I'm not sure I constellation understand your question. Are you trying to draw something in inches, but thw piece will only be drawn in cm?

If this is what your problem is, I believe it is an easy solution.

iLogic works in cm, which means that any numerical value you use will automatically be taken as a unit of cm.

To change into inches, simply multiply or divide by 2.54 according to what you want (ie. 2.54cm = 1inch).

Therefore multiply 4 * 2.54 to convert the value placed in iLogic into inches

Hope it helps

Regards
Mitch

*Kudo's if it works!
0 Likes