Is there Any code out there that will allow user to select part file then isolate and create view rep of that part with name of view rep the same as part.
The reason is we have lots of reps that isolate various components and this is very time consuming, I have had a look if there is Any customization because this would be a good user tool,also could work very well on assembly.
Any thoughts would be appreciated
I have noticed curtis waguespack has posted latest blog to get all file names and folder from parts using vb code vis selectset command.Code for this is below.
I am convinced with very minor tweaks and removing message boxes this code could be used to create my view rep via ilogic.
I have had a go at compiling code to do this but i am a just a beginner at vb,any help would be appreciated?
below is link to code that curtis posted for me to creat view rep by material type.
'get currently selected component Dim oOccurrence as ComponentOccurrence Try oOccurrence = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a component before running this rule.", "iLogic") Return End Try Dim doc As Document Dim CurFileName As String 'set the selected item oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1) 'get the selected item document occurrence name doc = oOccurrence.Definition.Document 'get the path and file name of the selected item CurFileName = doc.FullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) MessageBox.Show("File Name: " & Name _ & vblf & "File Name without extension: " & ShortName _ & vblf & "File Path: " & Folder_Location _ & vblf & "Path and File Name: " & CurFileName, "iLogic") '------------ end of ilogic--------------------
I think the rule in this text file will do what you're after. It creates a vew rep for each unique part in the assembly.
Note: This rule has a flaw (if you have two instances of a part in the assembly (PartA:1 and PartA:2) and you delete instance one (PartA:1), the rule does not make a view rep. It needs to be fixed so that it looks for the first instance of each part, rather than instance " :1" of each part, but havn't had time to get that sorted.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Here's the code for the rule, but beware of line wraps that might cause it to cut and paste incorrectly. Use the text file instead.
'create a design view representation for each unique part in the assembly 'define current document Dim openDoc As Document openDoc = ThisDoc.Document 'set a reference to the assembly component definintion. 'this assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'look at all of the components in the assembly Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define the first level components collection Dim oCompOcc As Inventor.ComponentOccurrence 'define view rep Dim oViewRep As DesignViewRepresentation 'define an arraylist to hold the list of view rep names Dim NameList As New ArrayList() 'Look at the view reps in the assembly For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepre
sentations 'set the list of names to the array list NameList.add(oViewRep.Name) Next 'check for a Default view rep and create it if not found If Not NameList.Contains("Default") Then 'create Default view rep oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepre sentations.Add("Default") oViewRep.ShowAll oViewRep.Activate End If 'zoom all ThisApplication.CommandManager.ControlDefinitions. Item("AppIsometricViewCmd").Execute 'look at all of the unique parts in the assembly For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then '12290 is the part document enumurator 'locate the last backslash position in the full file name Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) 'remove path from part file name Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'remove extension from part file name ShortName = Left(docFName, Len(docFName) - 4) 'check to see if the arraylist contains the desired view rep If Not NameList.Contains(ShortName) Then 'create new View Rep oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepre sentations.Add(ShortName) oViewRep.Activate oViewRep.Locked = False Else If NameList.Contains(ShortName) Then 'reference existing View Rep oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepre sentations.Item(ShortName) oViewRep.Activate oViewRep.Locked = False End If 'look at all of the occurences For Each oCompOcc in oCompDef.Occurrences 'locate the colon position in the occurence name oCompOccPos = InStrRev(oCompOcc.Name, ":") 'set occurence name to everything left of the colon oOccName = Left(oCompOcc.Name, oCompOccPos -1) 'set visible if name matches first occurence If oCompOcc.Name = ShortName & ":1" Then oCompOcc.Visible = True ThisApplication.ActiveView.Update() Else oCompOcc.Visible = False ThisApplication.ActiveView.Update() End If Next End If 'lock view rep oViewRep.Locked = True Next 'set Default View Rep active oAsmCompDef.RepresentationsManager.DesignViewRepre sentations.Item("Default").activate
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
I have been playing with code for a while and is very good at what it does but i was wondering can we take it to next level.
I still need view reps of parts same as before with rep name same as part without extension,however can we get it to only create a veiwrep if it finds text in a custom property called desc2
We controll all our manufactured parts that need some kind of machining opertation to it with internal code ie bevel/ , rout/,rip to pattern/ etc .
So we have create viewreps on dwgs for these parts to show operatives how to machine parts.normally this would not be a large task but some of our models have upto 20 isolated veiwreps per assembly and we have a lot of assemblys so it is very time consuming.
Any thoughts would be appreciated
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register