I didn't do any error checking and only tested it on one case but this will
at least provide a starting point. I tried to add enough comments that
hopefully you can make some sense out of it.
Public Sub ChangeLayerOfPart()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
' Call the function to find a specific node. The second argument of
this function
' is a string that would be within the full browser path of the node you
want to
' find. For example, if looking for an occurrence named Crank:1 that's
contained
' within the assembly 4Bar.iam, then you can use the search path
"4Bar.iam:Crank:1".
' The colon is used to seperate the individual components of the path.
(In this case
' one is also used in the name of the occurrence.)
Dim oNode As BrowserNode
Set oNode = GetBrowserNodeByName(oDoc.BrowserPanes.ActivePane.TopNode,
"4Bar.iam:Crank:1")
' Select the object represented by the node.
oNode.DoSelect
' Assuming the node represented a part within an assembly in a drawing
view, this
' then executes the "Select as Edges" command.
Dim oControlDef As ControlDefinition
Set oControlDef =
ThisApplication.CommandManager.ControlDefinitions.Item("SelectAsEdgesCtxCmd")
oControlDef.Execute
' Get the layer object that we want to use.
Dim oLayer As Layer
Set oLayer = oDoc.StylesManager.Layers.Item("Hidden")
' Iterate through the curves and change their layer.
Dim oDrawCurveSegment As DrawingCurveSegment
For Each oDrawCurveSegment In oDoc.SelectSet
oDrawCurveSegment.Layer = oLayer
Next
End Sub
Private Function GetBrowserNodeByName(ByVal TopNode As BrowserNode, ByVal
FullPathSearchString As String) As BrowserNode
Set GetBrowserNodeByName = Nothing
' Go through the child nodes of the node passed in.
Dim oSubNode As BrowserNode
For Each oSubNode In TopNode.BrowserNodes
' Check to see if this node is visible. Skip it if it is.
If oSubNode.Visible Then
' Check to see if the supplied search search is in the full path
of the current node.
If InStr(oSubNode.FullPath, FullPathSearchString) Then
' Set the return value and exit.
Set GetBrowserNodeByName = oSubNode
Exit Function
Else
' Check to see if this node has any children.
If oSubNode.BrowserNodes.Count > 0 Then
' Recursively call this function to traverse the tree.
Set GetBrowserNodeByName =
GetBrowserNodeByName(oSubNode, FullPathSearchString)
End If
End If
End If
Next
End Function
--
Brian Ekins
Autodesk Inventor API
wrote in message news:5205735@discussion.autodesk.com...
Is it possible to do the following thing
by code ?
Select a part in the Browser pane of an Drawing,
then mimic the select command, after that
start the command all edges and
move all the edges of the selected part to a new layer.
Kindest regards,
JesG