Showing posts with label dwf. Show all posts
Showing posts with label dwf. Show all posts

Thursday, 21 August 2014

Save As PDF DWF iLogic

A while back I posted a blog about locating a certain project folder on the network before doing the PDF, DWF export. I used a simple ilogic command calling the saveas function:

ThisDoc.Document.SaveAs(strNameDWF & (".dwf") , True)
ThisDoc.Document.SaveAs(strNamePDF & (".pdf") , True)

Unfortunately as in the save as Inventor dialog it only saves the first sheet. On save as you need to click on options to choose all sheets as well as "print in colors" and dpi resolution.

So just as in the Save As dialog where you need to click options to export all sheets we need to add more complex code:





I wanted to have all sheets exported and the dwf file to contain a full 3d model for better visualization and markup.

Her's how the final code looks like:


' set the filepath of the contracts folder to start with.
strStartFolder = "G:\Commercial & Engineering\Engineering\Contracts\"
' get the filename without extension
oFileName = ThisDoc.FileName(False)  
'get the project type by reading the first 6 
'digits of the filename EX 105280 or 105281
strFolderType = ( Left (oFileName,6)) 
'get the last 3 digits of the project no start 
'after first 7 digits of filename Ex 005 or 109
strFolderNo = (Mid (oFileName,7, 3)) 
'get the first 9 digits to compose project 
'type and number Ex 105281005 or 105281109
strFolderProj = ( Left (oFileName,9)) 
'et the document revision to use in the new filename
oRevNum = iProperties.Value("Project", "Revision Number") 

'Set folder for project based on Contract No
If strFolderNo < "100" Then
strFolder3 = "\001-099\"
ElseIf strFolderNo >= "100" Then
strFolder3 = "\100-199\"
ElseIf strFolderNo >= "200" Then
strFolder3 = "\200-299\"
End If

'Find folder in start path that contains Folder Type string 
Dim dir1() As String = System.IO.Directory.GetDirectories _
(strStartFolder, strFolderType & "*")
'Add Contract No folder to our folder
Dim dir2 As String = String.Concat(dir1) & strFolder3

'Find folder in new path containing Folder Type 
Dim dir3() As String = System.IO.Directory.GetDirectories _
(dir2, strFolderProj & "*")
'Add Drawing folder to our path
dir4 = String.Concat(dir3) & "\Drawing\"
dir5 = String.Concat(dir4) & "\PDF"

' verify if foder exists, create if not
If Not System.IO.Directory.Exists(dir5) Then
    System.IO.Directory.CreateDirectory(dir5)
End If

'------------------- Complex code added to save all sheets    ----------------
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDWFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
    oOptions.Value("All_Color_AS_Black") = 1
    oOptions.Value("Remove_Line_Weights") = 1
    oOptions.Value("Vector_Resolution") = 400
    'this publish all doens't work
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    'try a different publish all command
    'oOptions.Value("Publish_All_Sheets") = 1
    'oOptions.Value("Custom_Begin_Sheet") = 2
    'oOptions.Value("Custom_End_Sheet") = 4
End If

 'Set the PDF target file name
oDataMedium.FileName = dir5 & "\" & oFileName & "_Rev" & oRevNum & ".pdf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
i = MessageBox.Show("View the PDF file?", "Title",MessageBoxButtons.YesNo)
If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If 
If launchviewer = 1 Then ThisDoc.Launch(oDataMedium.FileName)


If oDWFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
    oOptions.Value("Launch_Viewer") = launchviewer
    oOptions.Value("Publish_All_Component_Props") = 1
    oOptions.Value("Publish_All_Physical_Props") = 1
    oOptions.Value("Password") = 0
    oOptions.Value("Publish_3D_Models") = Publish_3D_Models
    If TypeOf oDocument Is DrawingDocument Then
        Dim oSheets As NameValueMap
        oSheets = ThisApplication.TransientObjects.CreateNameValueMap
        oOptions.Value("Publish_Mode") = DWFPublishModeEnum.kCustomDWFPublish
        oOptions.Value("Publish_All_Sheets") = 1
        ' Publish the first sheet AND its 3D model
        Dim oSheet1Options As NameValueMap
        oSheet1Options = ThisApplication.TransientObjects.CreateNameValueMap
        oSheet1Options.Add("Name", "Sheet:1")
        oSheet1Options.Add("3DModel", True)
        oSheets.Value("Sheet1") = oSheet1Options
    End If
End If

 'Set the DWF target file name
oDataMedium.FileName = dir4 & oFileName & "_Rev" & oRevNum & ".dwf"
'Publish document
oDWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
i = MessageBox.Show("View the DWF file?", "Title",MessageBoxButtons.YesNo)
If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If 
If launchviewer = 1 Then ThisDoc.Launch(oDataMedium.FileName)
'------------------- End Complex code added In To save all sheets --------------


Again, thanks to Curtis Waguespack for his code that I've used here. Check his blog, he even has a code that does batch export for all components of an assembly.

Best of luck.
ADS.

Thursday, 31 July 2014

Locate folder for iLogic save as

Our design office uses vault for backup and history but the rest of the engineering department has it’s own folder on a mapped network drive. That’s where you’ll find contract specific files, as well as images, schedules, emails and literally anything that the project needs.
                So once a drawing is approved we get to release it to the engineering shared folder and need to place it in the project specific folders for dwf’s and pdf’s.
                This is a typical structure on the network of the engineering folder.
Root folder:
G:\Commercial & Engineering\Engineering\Contracts
where we have
105280-Pharmaceutical
105281-Industrial
105282-Scientific
105283-Healthcare
105285-Scotland

each split in hundreds for better navigation  by contract number:
001-099
100-199
200-299
                then we go project number and then drawing folder and pdf folder.
G:\Commercial & Engineering\Engineering\Contracts\105281-Industrial\100-199\105281109 – Project Description\Drawing\PDF
                My task was to create/modify existing ilogic to save current drawing as dwf and pdf each in it’s folder on the G drive.

                Here’s the code I came up with:

' set the filepath of the contracts folder to start with.
strStartFolder = "G:\Commercial & Engineering\Engineering\Contracts\"
' get the filename without extension 
oFileName = ThisDoc.FileName(False)   
' get the project type by reading the first 
'6 digits of the filename EX 105280 or 105281 
strFolderType = ( Left (oFileName,6))  
' get the last 3 digits of the project no start 
'after first 7 digits of filename Ex 005 or 109 
strFolderNo = (Mid (oFileName,7, 3))  
'get the first 9 digits to compose project type 
'and number Ex 105281005 or 105281109 
strFolderProj = ( Left (oFileName,9))  
'get the document revision to use in the new filename 
oRevNum = iProperties.Value("Project", "Revision Number") 

'Set folder for project based on Contract No
If strFolderNo < "100" Then
strFolder3 = "\001-099\"
ElseIf strFolderNo >= "100" Then
strFolder3 = "\100-199\"
ElseIf strFolderNo >= "200" Then
strFolder3 = "\200-299\"
End If

'Find folder in start path that contains Folder Type string 
Dim dir1() As String = System.IO.Directory.GetDirectories _
(strStartFolder, strFolderType & "*")
'Add Contract No folder to our folder
Dim dir2 As String = String.Concat(dir1) & strFolder3

'Find folder in new path containing Folder Type 
Dim dir3() As String = System.IO.Directory.GetDirectories _
 (dir2, strFolderProj & "*")
'Add Drawing folder to our path
dir4 = String.Concat(dir3) & "\Drawing\"

'set name for the new files, adding revision to end
strNameDWF = dir4 & oFileName & "_Rev" & oRevNum
strNamePDF = dir4 & "PDF\" & oFileName & "_Rev" & oRevNum

'Do the save operation
ThisDoc.Document.SaveAs(strNameDWF & (".dwf") , True)
ThisDoc.Document.SaveAs(strNamePDF & (".pdf") , True)

MessageBox.Show("All file formats saved in: " & dir4, "File Save")



                Hope it makes sense; I did struggle with the code ( I am not a programmer) but Curtis Waguespack's website was inspiring.

ADS

Thursday, 3 July 2014

iLogic Rules

I have just spent the last couple of days playing with iLogic. I am doing a tank template that I will present in the next couple of posts and it's all been done with iLogic and iFeatures.
Meanwhile I decided to present you a couple of iLogic routines and programs I am using. I have collected a couple and hope you will find them useful.
I don't have any programming experience, so all codes have been downloaded off the internet, tried and tested.
The main ones that I use are Export to PDF, DWF, and DXF. The reason I use ilogic is to automatically add revision to the filename. You can also chose export folder so one more thing out of the way.
I also use iLogic to force update iProperties of the drawing from the model. I have a code to set the scale of the model in the drawing and one to add virtual parts to the assembly from a text document. (Curtis Waguespack's code). He also gives a code to force turning all features off down level on all components (huge time saver)
Create a folder for your iLogic codes, recommend to use a map network drive location so they are available for all users in your company.
Open a file and go to Manage \ iLogic \ iLogic Browser , switch to External Rules tab. Right click and add external rule. Add your rules, in my case UpdateProps (force update of properties), SavePDF, SaveDXF, SaveDWF.


Switch to Global Forms and Add Form. If you have a common Design Data folder on the network then this Form will be available to all users ;) . Drag your rules on the right and change the name of the buttons and of the form if needed.



I know you can add buttons on the ribbon and quick access bar but you need to configure it with every new Inventor release so I prefer to have a global form instead.
At times I need to do a batch of files so I use Code Injector, a small utility that will do that for you. We once had around 900 drawings to export to dxf and pdf so we just left the injector run overnight. Here is the post and description. http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-triggers-automatically.html




Virtual Components
Issue:
You have a number of standard Virtual parts that you find yourself adding over and over. You'd like to have the ability to add them based on a predefined list.
Check his blog here for the code.
I use this to add various stuff like: oil for gearboxes and hydraulic units, paint and primer, chemical for anchor bolts, grout, etc.

Work Features
Issue:
You have other members of your design team that do not remember to turn off work features at the part level or sub-assembly level when they are done working with those files. As a result file previews and view representations get messed up. You'd like to have a quick way to toggle all of the work features off. Can this be done with iLogic?
 Check his blog here for the code.

Update copied properties.
Issue:
You have a lot of drawings that need update copied iproperties of the model (updates copied iproperties of the model in the drawing).
Solution:
Use the code to force the drawing to update copied properties from the model. Can be used with Code Injector to do a batch of drawings at a time.
File to be used: UpdateProps.iLogicVb

Save PDF
Issue:
You have to export one or many drawings at a time to pdf.
Solution:
Use the code to export current drawing to pdf. It creates (if didn't exist) a folder called DXF on same path as drawing (needs saving first) in which a pdfwith the filename being "Drawing_filename + Drawing_description + Revision". Can be used with Code Injector to do a batch of drawings at a time.
Make SURE that the drawing is saved otherwise the path of the folder and pdf will be on root drive.

Save DXF

Issue:
You have to export one or many drawings at a time to dxf.
Solution:
Use the code to export current drawing to dxf. It creates (if didn't exist) a folder called DXF on same path as drawing (needs saving first) in which a dxf with the filename being "Drawing_filename + Drawing_description + Revision". Can be used with Code Injector to do a batch of drawings at a time.
Make SURE that the drawing is saved otherwise the path of the folder and dxf will be on root drive.


Scale of first view in titleblock

In order to have the scale show up and update automatically in the titleblock, do the following.
Edit your title block definition and add a Text item with the type Prompted Entry
This text should contain <Scale>

After you add this, Inventor will prompt you for a Scale value whenever you add the title block to a sheet.
The same happens when you add a new sheet with the title block to the drawing or when you start a new drawing using a template where you have applied this solution.
When it prompts you, just leave the value blank

Then add the rule in text bellow to the drawing
File to be used: Prompted_Scale.txt
Add the rule to the trigger “Before Save Document”

After that, on every sheet in the drawing, you will get the scale value from the first view on that sheet in the title block when you save the file.


What rules do you use? Please let me kow what's your favorite?
ADS