Automatically generate a drawing

Automatically generate a drawing

Anonymous
Not applicable
2,821 Views
10 Replies
Message 1 of 11

Automatically generate a drawing

Anonymous
Not applicable
Would it be possible to use a macro to automatically generate a drawing of a sheet metal flat pattern?
0 Likes
2,822 Views
10 Replies
Replies (10)
Message 2 of 11

Rene-J
Collaborator
Collaborator
Hi
Try this code


Public Sub SMToIDW()

Dim oPartDoc As Document
Set oPartDoc = oApp.ActiveDocument

If oPartDoc.DocumentType <> kPartDocumentObject Then
MsgBox "The Active document must be a 'Part'"
Exit Sub
End If

' The Active document must be a Skeet metal Part
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Exit Sub
End If

'call drawing template'
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = oApp.Documents.Add(kDrawingDocumentObject, oApp.FileOptions.TemplatesPath & "Standard.idw", True)

'Delete Titleblock and Border
Dim oSheet As Sheet
Set oSheet = oDrawingDoc.ActiveSheet
oSheet.Size = kA3DrawingSheetSize
oSheet.Border.Delete
oSheet.TitleBlock.Delete

'set View scale to 1:1
Dim VScale As Double
VScale = 1

Dim oDrawingViews As DrawingViews
Dim oDV As DrawingView

Set oDrawingViews = oDrawingDoc.Sheets(1).DrawingViews


Dim oOptions As NameValueMap
Set v_org = oApp.TransientGeometry.CreatePoint2d(0, 0)

Set oOptions = oApp.TransientObjects.CreateNameValueMap
Call oOptions.Add("SheetMetalFoldedModel", False)

'Create flatpattern view
Set oDV = oDrawingViews.AddBaseView(oPartDoc, v_org, VScale, kDefaultViewOrientation, _
kHiddenLineRemovedDrawingViewStyle, , , oOptions)

'Adjust View skala to drawing
oDV.[Scale] = Viewscale(oDV.Width, oDV.Height)

'move View to 0,0
Set l_org = oApp.TransientGeometry.CreatePoint2d((oDV.Width / 2), (oDV.Height / 2))
oDV.Center = l_org

End Sub

Private Function Viewscale(ByVal viewL As Double, ByVal viewH As Double) As Double
If (viewL < viewH) Then
viewL = viewH
End If

viewL = (viewL * 10) 'from cm to mm
If viewL > 250 Then
Viewscale = (1 / (viewL / 250))
Else
Viewscale = 1
End If

End Function
Message 3 of 11

Anonymous
Not applicable
Thanks for the guidance, I'll give it a go!
0 Likes
Message 4 of 11

Anonymous
Not applicable
A couple of modifications -
Set oPartDoc = ThisApplication.ActiveDocument
If oPartDoc.DocumentType <> kPartDocumentObject Then
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
all "oDoc" changed to "ThisApplication"
and it does what it says on the tin!!
Thank you very much.
0 Likes
Message 5 of 11

Anonymous
Not applicable

Hi Peter, Ive been 3d modelling for 10+ years however my macro/vb/c++ skills are zero.

I contracted for a company 3 years ago who used solid works (yuk) however a programmer there had created a macro that produced from an assembly file:

1. Individual pages of every part with in the assy

2. Plan orthographic views and a section view... on each page to a scale that suited the page, (as scale rules etc arent as widley used these days, a random scale is sufficient.

 

Im pretty sure the programing language is similar between Inventor and Solid works, if I sent you that code do you think you could adapt it to be used for Inventor?

Look forward to a response.

 

Could you please also point me in the right direction for a macro that can: open part from directory, create flat pattern, save, close file, open next file in directory...repeat . I would be very geatfull.

 

heres a link to the post.

http://forums.autodesk.com/t5/Autodesk-Inventor/Automate-part-placement-on-an-idw-from-an-iam/m-p/27...

 

Regards, Stefan.

0 Likes
Message 6 of 11

Anonymous
Not applicable

Hi there I was wondering if you can help me with the following:

Can you point me in the right direction for a macro that can: open part from directory, create flat pattern, save, close file, open next file in directory...repeat 290 times. I would be very greatfull.

regards Stefan.

0 Likes
Message 7 of 11

Rene-J
Collaborator
Collaborator

Hi Stefan

Try this Addin  iFlatpatternExport 

http://www.mcadforums.com/forums/viewtopic.php?f=34&t=11249

 

In The addin

Set  Auto export on save sheetmetal part

set  on save create flattpattern if not exist

Use the Inventor task scheulder

create a task update design, select  directory,  select *.ipt in filename

and run the task.

 

René J

  

1126i60495B4243F18CBB

 

 

0 Likes
Message 8 of 11

Anonymous
Not applicable

I wrote a sucessful add-in that included the generation of a flat pattern if one didn't exist.  But that was back a while, maybe R9 or R10.

 

Currently I don't recommend trying to automatically create a flat pattern due to the rather illogical way IV now creates a flat pattern if you don't select the base face (something seems to have changed).  It may be my code, but if I automatically create a flat pattern it is invariably the wrong hand! 

See

http://forums.autodesk.com/t5/Autodesk-Inventor/Illogical-sheet-metal-flat-pattern/m-p/2558612

 

Rene, I'll give your add-in a try.

0 Likes
Message 9 of 11

Anonymous
Not applicable

Thanks very much, i'll give that a crack.

 

Stefan

0 Likes
Message 10 of 11

Anonymous
Not applicable

Thanks Peter,Out of habbit I always choose the base face generally, (according to good face, folds down for sheetmetal drawings)

Luckily this job has no folds, and inventors random approach on this one occasion will be ok.

 

p.s I used to develop some tricky sheetmetal parts,and as you would know, the flat pattern some times wont generate at all untill you manually go through every possible face. I remember the days of mechanical desktop along with the add in Autopol, that would unfold almost anything, it would even unfold a deep drawn flange or pocket that had no corner seams.

 

Thanks again,

Stefan

0 Likes
Message 11 of 11

Anonymous
Not applicable

I know this post is really old but would you be willing to help edit your macro a little.  I have almost no coding experience and can't get it to do what I want.

0 Likes