Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Returning the File Name of a Selected View's Part

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jmfowler1996
895 Views, 5 Replies

Returning the File Name of a Selected View's Part

Hey guys.

 

I recently had an idea which I need help with.

 

1. Basically, I want to create lots of parts and name them something like this:

[thickness] THK [material] [part number] [description] QTY [quantity].

 

2. I would then use an iLogic rule from a drawing to set the existing 'view' variable of a selected part view to be equal to the part number and description (using an array).

     -note: I don't want to override the view label to replace "<VIEW>" with anything.

 

3. Lastly, the iLogic rule would modify the label to add various lines with the rest of the info.

 

 

Obviously there is no problem with the first part.

 

For the second part, I am thinking of using this:

tmpView.Name = "..."

 , but I am not sure how to get the file number of the view's part. With that, I could just use an array and pick out the bits I need.

 

For the third part, I will be using

oView.Label.FormattedText = "<VIEW>" & ...

 but again need something which returns the file name of the part of the selected view. I will then use arrays again.

 

 

Any ideas?

Cheers,

Jonathan.

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: jmfowler1996

Hey Jonathanan,

 

Hope my piece of code might be helpful to determine the filename of the part to which the view is selected.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartName As String
oPartName = oDrawDoc.SelectSet.Item(1).ReferencedFile.DisplayName
MessageBox.Show(oPartName, "Part Name")

 If there is too many view selection you can add the for each loop to iterate filename. In this code it works only for one view selection.

Message 3 of 6
jmfowler1996
in reply to: Anonymous

Thanks for the reply, Srinivas.

 

I will test this tomorrow and post my results. This looks like what I am after though. 

 

Thanks,

Jonathan.

Message 4 of 6
jmfowler1996
in reply to: jmfowler1996

For anyone who is trying something similar, this is the iLogic I used - it may be a bit messy as I have just stitched together bits of info I could find, nevertheless, it works just fine.

 

 

On Error Resume Next

Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
MessageBox.Show("You must select a drawing view first", "iLogic")
Exit Sub
End If
'Reference to the drawing view from the 1st selected object
For Each oView In oSSet

'Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView)
If oView IsNot Nothing Then
oView.ShowLabel = True

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartName As String
oPartName = oView.ReferencedFile.DisplayName


'split part name
Dim arr() As String
Textstring = oPartName
arr = Split(Textstring, " ")

'find description
cumulativeDescription=""
For i = 4 To arr.length-3
    cumulativeDescription=cumulativeDescription + arr(i) + " "
Next i
cumulativeDescription=Left(cumulativeDescription, cumulativeDescription.length-1)

'set variables
myType=UCase(arr(0))
myThickness=arr(1)
myMaterial=UCase(arr(3))
myDescription=cumulativeDescription
myQuantity=arr(arr.length-1)

'MessageBox.Show(myType & " - " & myThickness & " - " & myMaterial & " - " & myDescription & " - " & myQuantity, "info")


'format the model iproperties
oDescription = "<StyleOverride Underline='True' FontSize='0.2'><DrawingViewName/></StyleOverride>"
oMaterial = "<Br/><StyleOverride Underline='False' FontSize='0.2'>" & myThickness & " THK " & myMaterial & "</StyleOverride>"
oQuantity = "<Br/><StyleOverride Underline='False' FontSize='0.2'>" & myQuantity & "-OFF REQD" & "</StyleOverride>"
oStringScale = "<Br/><StyleOverride Underline='False' FontSize='0.2'>SCALE <DrawingViewScale/></StyleOverride>"

'oView.Name = oPartName
oView.Name = myDescription

'add to the view label
oView.Label.FormattedText = oDescription & oMaterial & oQuantity & oStringScale

Else
MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If

Next

 

This works for part files with filenames as follows:

[TYPE] [THICKNESS] THK [MATERIAL] [DESCRIPTION] QTY [QTY]

e.g.

PLATE 10 THK S355 TOP FLANGE QTY 2

Message 5 of 6
Anonymous
in reply to: jmfowler1996

You can make your iproperty split to fill out your custom iproperty. In the code below I’m taking the file name and splitting it to fill out two separate custom iproperty. the "-" will split the file name.

 

For example:

     File name: 0984-P03

                Custom Job iproperty = 0984

                Custom Job iproperty = P03

 

'MarkNumber and Job Information
iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False) 'without extension

Try 'Filename Convert
Part_Number = iProperties.Value("Project", "Part Number") Job_Split = Split(Part_Number, "-")(0) Mark_Split = Split(Part_Number, "-")(1) iProperties.Value("Custom", "Job") = "=" & Job_Split iProperties.Value("Custom", "MarkNumber") = "=" & Mark_Split Catch End Try

 

I hope this helps.

Message 6 of 6
jmfowler1996
in reply to: Anonymous

Thanks for your reply.

 

This method is quite similar to the one which I have used in the code I posted earlier. On the line:

arr = Split(Textstring, " ")

i split the filename of the part by the spaces so that I can use each part separately.

In this case, I did not actually want iProperties to be filled, as firstly, I expect to have upwards of 50 views on some drawings. Obviously I cannot have drawing iProperties for them all (unless you meant part iProperties). Secondly, the variables were to be inserted into the view label.

 

I have, however found this type of code useful in splitting a file location by "\" and because we have all projects in a client specific folder, (with the same name as the client), I was able to set the drawing's "Client" iProperty automatically to that part of its file location. I also did this with several other iProperties too.

 

Thanks again,

Jonathan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report