vba help!!

vba help!!

Anonymous
Not applicable
537 Views
3 Replies
Message 1 of 4

vba help!!

Anonymous
Not applicable

hi..

 

what is the code in selecting a sketch block from the browser in vba?

i only need to get the name of the block selected..

solid2.jpg

 

 

0 Likes
Accepted solutions (1)
538 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

 

    Enjoy mate.. Here is the code...

    Give Some Kudos and accept as Solution Smiley Happy 

 

Sub SketchSel()
Dim prtdoc As PartDocument
Set prtdoc = ThisApplication.ActiveDocument
Dim prtdef As PartComponentDefinition
Set prtdef = prtdoc.ComponentDefinition

Dim sk As PlanarSketches
Set sk = prtdef.Sketches
Dim osk As PlanarSketch
For i = 1 To prtdef.Sketches.count
   Set osk = prtdef.Sketches(i)
    For j = 1 To osk.SketchBlocks.count
        If InStr(osk.SketchBlocks(j).Name, "Steel") Then
            prtdoc.SelectSet.Select prtdoc.ComponentDefinition.Sketches(i).SketchBlocks(j)
        End If
    Next
Next
End Sub

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

this is in red:

 prtdoc.SelectSet.Select prtdoc.ComponentDefinition.Sketches(i).SketchBlocks(j)

 

am i correct to say that the code is predefining the blocks name as whatever (eg. steel)??

 

what i would like to do is select the block from the browser and not hardcode it .is it doable?

 

thanks..Smiley Indifferent

0 Likes
Message 4 of 4

Anonymous
Not applicable

Check my answers in RED 

 

prtdoc.SelectSet.Select prtdoc.ComponentDefinition.Sketches(i).SketchBlocks(j)

 

Make sure you got a part document as opend file in Inventor.

 

am i correct to say that the code is predefining the blocks name as whatever (eg. steel)??

 

Yes..  the code is looking for blocks with name(string) contains "Steel".

 

what i would like to do is select the block from the browser and not hardcode it .is it doable?

 

You need to have a find or search function where you can enter name of block to be selected and code will highlight that block

0 Likes