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

each split in hundreds for better navigation  by contract number:
                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.


Thursday, 24 July 2014

Quick Properties and Shift Deselect

Short posts today on a couple of issues I had with Autocad.
                First tip is disabling the Quick Properties Window. If every time you select an object on Autocad you get a pop-up properties window then you’ve enabled the quick properties display option. What’s worse is that it doesn’t have a name or title so you can’t really tell what you've activated.

                You can type QPMODE and change it to 0.

                Or you can click on the customisation menu on the right down corner, add Quick Properties to the expanded menu and then click on the new icon to turn it on/off.

Here’s the help page description.

Saved in:
Initial value:
Sets the on or off state of Quick Properties palette.
Turns off the display of the Quick Properties palette for all objects. When turned back on by clicking Quick Properties on the status bar, QPMODE is set to 1
Turns on the display of the Quick Properties palette for all objects
Turns on the display of Quick Properties palette only for objects that are defined in the Customize User Interface (CUI) Editor to display properties
Note When this system variable is set to a negative number, the feature is turned off but the value is retained.

                Second tip regards the wrong behaviour of shift to deselect objects. It seems Raster Design has an option to “Shift+Left Click to Image select”. The shift hijack can be turned off by typing IOPTIONS and deselecting the “Shift+Left Click to Image select” in the User Preferences tab.


Thursday, 17 July 2014

Rounding Inventor Parameters

The other day I was looking to round the value of a parameter. I was actually calculating distance from the floor to the top of a flange on a conical tank and the value came with billion digit precision. It's nice to have it but it doesn't look professional when dimensionsing or measuring from it.
Couple of words on rounding parameters and using functions:
The following are the supported functions as presented in the Autodesk Inventor help page.

Returns Unit Type
Expected Unit Type
any (Return 0 if negative, 1 if positive.)
any (Return exponential power of expression: for example, return 2 for 100, 3 for 1000, and so on.)
unitless (Next lowest whole number.)
unitless (Next highest whole number.)
unitless (Closest whole number.)
any and unitless, respectively

The last one isolate is used to change from one unit to another and this if usefull if you need to calculate the number of holes (of type unitles ul) by dividing a linear dimension (of unit mm) by another linear dimension (of unit mm). The normal result will be of type mm and you need to convert it to unitless ul like this:
isolate((total_length / hole_dist); mm; ul)
Now I was looking to round the result of an equation to an integer but the result was surprising.

Round 1497.21 = 1500 ?!?
Ceil 1497.21 = 1500 ?!?
Floor 1497.21 = 1490 ?!?

Round 1497.00 = 1500 ?!?
Ceil 1497.00 = 1500 ?!?
Floor 1497.00 = 1490 ?!?

Round 1497.51 = 1500 ?!?
Ceil 1497.51 = 1500 ?!?
Floor 1497.51 = 1490 ?!?

So in order to get a proper rounding you need to multiply it first by a multiple of 10, then do the operation and divide again by the same 10 multiple.

Round (1497.21 * 10) /10 = 1497
Ceil (1497.21 * 10) / 10 = 1498
Floor (1497.21 * 10) / 10 = 1497

Round (1497.00 * 10) /10 = 1497
Ceil (1497.00 * 10) / 10 = 1498
Floor (1497.00 * 10) / 10 = 1497

Round (1497.51 * 10) /10 = 1498
Ceil (1497.51 * 10) / 10 = 1498
Floor (1497.51 * 10) / 10 = 1497

I am missing something and it's got to do with the unit conversion for sure, but for now this will do.

Hope it helps you as well.

EDIT 16-02-2016:
There is an update for this so come check it out here.

Thursday, 10 July 2014

AutoCAD advanced search replace

A couple of words on Autocad search replace. Autocad has the functionality built in and for simple things is good enough.
For example when I need to change pipe size on a P&I D I can select the labels and use the properties (CTRL+1) to change the attribute text all at once.

If you need to change different types of notes, blocks, texts, multiline-text etc. then you can use the Search/Replace functionality

You can search in Entire drawing / Current space/layout or in selection (pre selected object or on the spot)

On the result list you can select just part of the items before doing replace.

But what if you need to do a complex search replace? This won’t do.
I had to change Cable Schedule in several acad drawings and all I was given was an excel file.  Luckily I had the previous revision of the excel file and I could make a list of old - new name. Lee Mac has created a script that can do that for you. The script is called BFind and here’s how I used it.
                 This is what the Acad looks like.
                 And this is what we will end up with.

Once you load the BFindV2-0.lsp script in you acad session (you can drag drop it on your drawing) run it by typing BFind and you should get the following window.

In here you can search replace in current drawing, all open drawings, folder,  folder with subfolders. You don’t want to type all text changes one at a time but rather use a text document with the values from excel so here’s how to do that.
You need to add something in the search replace fields and save it as a text for reuse late. You can then open the reuse text document and add your texts. Load it back in the BFind window an hit ok.

Let’s add Find: ADS ad Replace with: ADS1 then click Save. Click OK for changes to take effect and then open windows explorer and let’s locate the file.  Do a search on C: drive for a file name that contains LMAC BFind. Mine was located here:
C:\Users\adrian.salariu\AppData\Roaming\Autodesk\AutoCAD Mechanical 2015\R20.0\enu\Support\LMAC_BFind_SavedSearches_V2-0.txt
Open it up and check to make sure it contains our saved Search Items List.

Add your text in and save the document. In Autocad run BFind and click on Load to load your list.
After selecting your search location (drawing, folder , etc.) click OK and go get a coffee till it’s done.

This saved me a couple of hours of boring, mind-numbing work. Hope it helps you as well. Here's the link to Lee's web page.


Quick Inventor Parameters

I have been working on a tank template driven with ilogic and ifeatures and I needed to add a lot of parameters for all my connections.
You can go to Inspect \ Parameter and use Export Parameters to get them out in xml format. You can then edit this with Notepad or any text editor and add your changes. You can add new values to a Multi-Value parameter or add new parameters.

I have copied one set and used paste and then replace to change the parameter name and values.
Then I have saved and imported the file back in Inventor to get them in my template.

A parameter starts with <ParamWithValue> and ends with <\ParamWithValue> just like my example bellow.
      <comment>Connection 10 size</comment>


Wednesday, 9 July 2014

Autocad Object Slection

A while ago I posted a blog on the autocad selection tools and now I am returning a bigger list of options for Select command. Greg Battin has put a list together and I’ve decided to share it here.

“Options when selecting objects
When you are asked to “Select Objects: ” you have options.
before selecting objects when prompted to do so, (even in the above command) choose one of these options:
§  W for Window
§  L for Last
§  C for Crossing
§  BOX
§  ALL
§  F for Fence
§  WP for WPolygon (Window Polygon
§  CP for CPolygon (Crossing Polygon)
§  G for Group
§  A for Add
§  R for Remove
§  M for Multiple
§  P for Previous
§  U for Undo
§  AU for AUto
§  SI for SIngle
§  SU for SUbobject

§  O for Object”

Thank you Greg,


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.

Virtual Components
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
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.
You have a lot of drawings that need update copied iproperties of the model (updates copied iproperties of the model in the drawing).
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
You have to export one or many drawings at a time to pdf.
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

You have to export one or many drawings at a time to dxf.
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?

Wednesday, 2 July 2014

Dimensioning Arc Tangent

I was hoping by now it got fixed but even in AIP 2015 if you need to dimension tangent to an arc and you have center line, you need to get the center line out of the way first. It doesn't snap to arc or circle until you move the center line.

In my case I needed the overall width and I can't snap to edge of circle.
 So I had to move the center mark line firs (drag it towards center)
 Now tangent becomes available for selection
 End result