It is currently Thu May 23, 2013 3:24 pm

All times are UTC





Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: MACRO: SaveAsDerived
PostPosted: Thu Apr 27, 2006 12:20 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
I have been meaning to write this for a while but got sidetracked. This macro will create a derived part from the current active part.

In my workflow I often want to create a derived part from the current open part. Currently you have to open a new part template, start the derived part command and then find the file you already have open.

Using this macro you can just click a button and it starts a new part file and begins the derive part command based on the active part or assembly file.

To use create a module named SaveAsDerived and paste in this code. Then place the BMP icon in the same directory as your active IVB file (Default.ivb most likely). Restart IV and then got to Tools>Customize>commands>Macros and you should see the macro and icon button. Drag it to your toolbar.

You can specify which template to use by editing the code as instructed below.

Maybe one day I'll turn this into a real add-in.


Watch for word wrap when pasting code...
Code:
Public Sub SaveAsDerived()

'written by and property of Sean Dotson, copyright 2006
'if you plan to use this code be my guest, just drop me a line
'to let me know you are...

'declare the environment
Dim oApp As Application
Dim oCurrentDoc As Document
Dim oNewDoc As Document
Dim UseDefaultTemplate As Boolean
Dim sCurrentFileName As String
Dim sTemplatePart As String

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument
   
Select Case oApp.ActiveDocumentType

Case kAssemblyDocumentObject, kPartDocumentObject

    sCurrentFileName = ThisApplication.ActiveDocument.FullFileName
   
    If sCurrentFileName = "" Then
        MsgBox "The active file must first be saved"
        Exit Sub
    End If
   
    'if you want to use the default template then set UseDefaultTemaplte = True
    'if you want to use a custom template set the path and filename of sTemplatePart and UseDefaultTemaplte = False
   
    UseDefaultTemplate = True
    sTemplatePart = "K:\Inventor R9 Templates\_RND\Std Part.ipt"
   
    Select Case UseDefaultTemplate
        Case True
            Set oNewDoc = oApp.Documents.Add(kPartDocumentObject)
        Case False
            Set oNewDoc = oApp.Documents.Add(kPartDocumentObject, sTemplatePart, True)
    End Select

'******START UPDATED CODE **************
'If your template has an active sketch you need to close it.
    Dim oSketch As Sketch
    On Error Resume Next
    Set oSketch = oNewDoc.ComponentDefinition.Sketches.Item(1)
    oSketch.ExitEdit
    On Error Goto 0
'******END UPDATED CODE **************

    'Get the control definition that represents the derived part command.
    Dim oDerivedCommandDef As ControlDefinition
    Set oDerivedCommandDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartDerivedComponentCmd")
   
    'Post the filename to the private event queue.
    Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sCurrentFileName)
       
    'Start the derived part command.
    oDerivedCommandDef.Execute

Case Else
    MsgBox "You must first have a Part or Assembly document open"

End Select

End Sub


You do not have the required permissions to view the files attached to this post. You must LOGIN or REGISTER to view these files.

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Last edited by SeanDotson on Fri May 05, 2006 12:16 pm, edited 5 times in total.

Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 3:32 am 
Offline
MCAD Contributer

Joined: 14 Apr 2004
Posts: 143
Country: United States
State: Alabama
CAD System: Inventor
Sean,
Much appreciated. There is something similar to this in R11, Assembly Tools menu. It works from the assembly environment.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 11:04 am 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
This should work in both environments.

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 12:32 pm 
Offline
Content Manager

Joined: 20 Feb 2004
Posts: 698
Country: Netherlands
State: Non US/CAN Resident
CAD System: Wildfire-ProE
Don't you just love the creativity of the users, who always think "one step further" :-D


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 12:56 pm 
Offline
MCAD Lurker

Joined: 28 Apr 2006
Posts: 4
It does not work with my own template (((
It just open new file and stop....


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 1:06 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
It does work with custom templates. You need to change:

UseDefaultTemplate = True

to

UseDefaultTemplate = Flase

and put the path to your template file in

sTemplatePart = "K:\Inventor R9 Templates\_RND\Std Part.ipt"

You have to make sure it is 100% correct however. Any typos will cause it to crash.

Is this on R11 or R10?

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 4:31 am 
Offline
MCAD Lurker

Joined: 28 Apr 2006
Posts: 4
SeanDotson wrote:
It does work with custom templates. You need to change:

UseDefaultTemplate = True

to

UseDefaultTemplate = Flase

and put the path to your template file in

sTemplatePart = "K:\Inventor R9 Templates\_RND\Std Part.ipt"

You have to make sure it is 100% correct however. Any typos will cause it to crash.

Is this on R11 or R10?


I have R10. If I have any typos - macro don't work an all. In my case it create a new file, nothing else... ( no derived part included).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 11:24 am 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
Don't know what to tell you. I have tried this on several machines and it works fine. Sorry.

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 9:22 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
OK, I found the likely problem. If your templte has an open sketch (when you start a new part from it if you are already in an active sketch) you need to get out of it first.

To do this you need to change the code a bit. See the original post for the changes.

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 6:57 am 
Offline
Content Manager

Joined: 20 Feb 2004
Posts: 698
Country: Netherlands
State: Non US/CAN Resident
CAD System: Wildfire-ProE
Code:
'******START UPDATED CODE **************
    Dim oSketch As Sketch
    On Error Resume Next
    Set oSketch = oNewDoc.ComponentDefinition.Sketches.Item(1)
    oSketch.ExitEdit
    On Error Goto 0
'******END UPDATED CODE **************


This will also solve the problem if your template has got more than one sketch (Inventor will not activate any sketch)

And these are missing too:

Dim sCurrentFileName As String
Dim sTemplatePart As String

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 4:42 am 
Offline
MCAD Lurker

Joined: 28 Apr 2006
Posts: 4
SeanDotson wrote:
OK, I found the likely problem. If your templte has an open sketch (when you start a new part from it if you are already in an active sketch) you need to get out of it first.

To do this you need to change the code a bit. See the original post for the changes.



Thank you! Now it is working!!!!


Top
 Profile  
 
 Post subject: Save As Derived Macro
PostPosted: Tue May 09, 2006 1:57 pm 
Offline
MCAD Lurker

Joined: 05 May 2006
Posts: 2
Thank you for creating this, just what I needed to make my life a little simpler.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 8:56 pm 
Offline
MCAD Contributer
User avatar

Joined: 09 May 2006
Posts: 89
This is just what I need except I need to also do a uniform scale in the process. I have no VB experience. Can someone please chime in with advice?

Also KArthur referred in his post about somthing like this in R11. Would this be Batch Publish? Or is there something else I haven't seen.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 9:00 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
All this does is start the derived command. You can enter the scale when it fires up..

Re: R11 addins, see this thread

http://www.mcadforums.com/forums/viewtopic.php?t=5210

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY