Is there a way to associate layers to materials so when they are placed in a drawing they are automatically placed on the proper layer. I have line weights set for each individual layer and would like each material component to have its own line weight.
Solved! Go to Solution.
Solved by MjDeck. Go to Solution.
Solved by MjDeck. Go to Solution.
Solved by MjDeck. Go to Solution.
It might be possible. It would be easier in Inventor 2011. Are you running 2011?
The closest thing I can find was from Brian Ekins "modthemachine"
http://modthemachine.typepad.com/
Can someone further explain what Mr. Ekins was discussing when you wrote "It also uses the Sheet.ChangeLayer method which is a new method in Inventor 2011 that changes the layer of a group of objects"
I basically would like to have Inventor see a part in the idw enviroment and assign it to the proper layer. This way all my line weights will be correct.
I would appreciate any feed back, Thank you all
Here's an iLogic rule to change layers according to the material. It's based on Brian's code (in his Changing Drawing Curves to Match Assembly Color post).
There's no way to make this rule run when you place a new view, but you can make it run every time you save the drawing. Start the Event Triggers command, and add this rule to the Before Save Document event.
Sub Main drawDoc = TryCast(ThisDoc.Document, DrawingDocument) If (drawDoc Is Nothing) Then MessageBox.Show("This rule can only be run in a drawing,", "iLogic") Return End If ChangeLayerOfOccurrenceCurves() End Sub Private drawDoc As DrawingDocument Public Sub ChangeLayerOfOccurrenceCurves() ' Process the occurrences, wrapping it in a transaction so the ' entire process can be undone with a single undo operation. Dim trans As Transaction trans = ThisApplication.TransactionManager.StartTransaction(drawDoc, "Drawing Layers by Materials") Try For Each dSheet As Sheet In drawDoc.Sheets For Each drawView As DrawingView In dSheet.DrawingViews ' Call the recursive function that does all the work. Dim docDesc As DocumentDescriptor docDesc = drawView.ReferencedDocumentDescriptor If (docDesc Is Nothing) Then Continue For If (docDesc.ReferencedDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then Continue For Dim asmDef As AssemblyComponentDefinition asmDef = docDesc.ReferencedDocument.ComponentDefinition Call ProcessOccurrences(drawView, asmDef.Occurrences) Next Next Catch ex As Exception trans.Abort() Throw ex End Try trans.End() End Sub Private Sub ProcessOccurrences(ByVal drawView As DrawingView, _ ByVal Occurrences As ComponentOccurrences) ' Iterate through the current collection of occurrences. Dim occ As ComponentOccurrence For Each occ In Occurrences If (occ.Suppressed) Then Continue For If (occ.Definition Is Nothing) Then Continue For ' Check to see if this occurrence is a part or assembly. If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then ' ** It's a part so get the material Dim subDoc As Document = occ.Definition.Document If (subDoc Is Nothing) Then Continue For Dim partDoc As PartDocument = subDoc Dim materialName = partDoc.ComponentDefinition.Material.Name ' Get the TransientsObjects object to use later. Dim transObjs As TransientObjects transObjs = ThisApplication.TransientObjects ' Verify that a layer exists for this material. Dim layers As LayersEnumerator layers = drawDoc.StylesManager.Layers On Error Resume Next Dim newLayer As Layer newLayer = layers.Item(materialName) If Err.Number <> 0 Then On Error Goto 0 ' Copy an arbitrary layer giving it the name ' of the material. newLayer = layers.Item(1).Copy(materialName) ' Set the attributes of the layer to use the color, ' have a solid line type, and a specific width. ' newLayer.Color = newColor newLayer.LineType = LineTypeEnum.kContinuousLineType 'newLayer.LineWeight = 0.02 End If On Error Goto 0 ' Get all of the curves associated with this occurrence. On Error Resume Next Dim drawcurves As DrawingCurvesEnumerator drawcurves = drawView.DrawingCurves(occ) If Err.Number = 0 Then On Error Goto 0 ' Create an empty collection. Dim objColl As ObjectCollection objColl = transObjs.CreateObjectCollection() ' Add the curve segments to the collection. Dim drawCurve As DrawingCurve For Each drawCurve In drawcurves Dim segment As DrawingCurveSegment For Each segment In drawCurve.Segments objColl.Add(segment) Next Next ' Change the layer of all of the segments. Call drawView.Parent.ChangeLayer(objColl, newLayer) End If On Error Goto 0 Else ' It's an assembly so process its contents. Call ProcessOccurrences(drawView, occ.SubOccurrences) End If Next End Sub
MjDeck,
Thank you very much for your time and effort.
When I copy and paste the code into a rule, I am receiving
Line 16 : End of statement expected
trans = ThisApplication.TransactionManager.StartTransactio?n(drawDoc, "Drawing Layers by Materials")
Take out the ? in StartTransactio?n.
It looks like some data corruption happened in copying and pasting the rule. Here's a fresh copy of the rule attached as a text file.
It only works on drawing views that show an assembly. Do you need it to work on drawings that have views of parts? I can change it to support views of parts if required.
I will need it to be able to do both, once my assembly is completed and the client approves the drawing. Then I will have to break down each part and generate fabrication drawings.
I just add colors and assigned them to each material. I named the color the same name as my material and layer.
Assignment: "I think, correct me if I am wrong"
Color > Material > Run Rule > Layer
Do you want the rule to take the color from the material and apply it to the drawing layer? It won't do that now. It doesn't change the layer at all (if the layer already exists). The way it is now, it's up to you to set the layer color.
Here's a new version that works with views of parts or assemblies.
Just tested it and it look really great, I really appreciate all your help.
Looking one step further, I realize that it is making the hidden lines (Linetype) continues. That is due to the fact that the layer it is assigned is set for continues line type. Would you have any suggestions dealing in regards to the hidden line appearance?
I see what you mean. That's not good. Do you want to leave all the hidden lines on the Hidden layer, or do you want to create a new hidden layer for each material?
Yes, it will be able to move the hidden lines to the particular hidden line layer for that material. It could also create the layer automatically. It would copy the solid-line material layer, and change the line type to dashed.
I should have a new version of the rule posted soon.
Mike,
When I utilize the rule for the first time everything work properly. The layers change according as planned, however I am noticing after I assign dimensions and leaders and have all the drawing views completed the rule stops working. When I manual run the rule I receive errors. I have listed those errors below, please let me know what you think. Thank you
Rule Compile Errors in Assign Layers, in Laundry Room.dwg
Error on Line 3 : Class 'LmiRuleScript' must implement 'Sub Main()' for interface 'Autodesk.iLogic.Interfaces.IRuleInterface'.
Error on Line 25 : 'Public Sub Main()' has multiple definitions with identical signatures.
Error on Line 36 : 'Public Sub ChangeLayerOfOccurrenceCurves()' has multiple definitions with identical signatures.
Error on Line 49 : Statement cannot appear within a method body. End of method assumed.
Error on Line 49 : 'Public Sub Main()' has multiple definitions with identical signatures.
Error on Line 10 : 'drawDoc' is already declared as 'Private drawDoc As Inventor.DrawingDocument' in this class.
Error on Line 12 : 'Public Sub ChangeLayerOfOccurrenceCurves()' has multiple definitions with identical signatures.
Error on Line 25 : Statement cannot appear within a method body. End of method assumed.
Error on Line 34 : 'drawDoc' is already declared as 'Private drawDoc As Inventor.DrawingDocument' in this class.
Based on those error messages, I think you might have two copies of the same rule in the file. Did you copy and paste twice into the same rule? Please delete the rule, and then add a new rule and copy and paste the text from DrawingLayersByMaterials.txt above into it.
I am working on a new version of the rule to support hidden lines.
Ok, that did the trick
Thank you
I also have two layers: one called (Stone-Cyan & another Stone-Magenta)
In a drawing view I would like the stone material to be Stone-Cyan but in a section view we would like it to be Stone-Magenta. Would this be possible? Due to the fact that in section the line weight should be slightly darker according to basic standards.
Maybe you need 4 layers for each material?
00-Stone-Cyan
00-Stone-Magenta
00-Stone-Cyan-Hidden
00-Stone-Magenta-Hidden
Otherwise, the dashed lines will show up in a different color than the solid lines.
You only want to use 00-Stone-Magenta (and maybe 00-Stone-Magenta-Hidden) in the section views, right?
I might have to include a table in the rule, where you can list the names of layers to be used in the projected and section views.
You only want to use 00-Stone-Magenta (and maybe 00-Stone-Magenta-Hidden) in the section views, right?
Correct
I might have to include a table in the rule, where you can list the names of layers to be used in the projected and section views.
Projected views would be 00-Stone-Cyan & 00-Stone-Cyan-Hidden
Section, Auxiliary & Detail views would be 00-Stone-Magenta & 00-Stone-Magenta-Hidden
Can't find what you're looking for? Ask the community or share your knowledge.