iLogic code to turn sketch block visibility on and off

iLogic code to turn sketch block visibility on and off

PaulMunford
Community Manager Community Manager
1,760 Views
3 Replies
Message 1 of 4

iLogic code to turn sketch block visibility on and off

PaulMunford
Community Manager
Community Manager

Hey chaps.

 

I'va managed to cobble this code together to turn some sketch visibilities on and off. However, what I'd really like to do is have a single sketch containg some blocks, and turn the visibility of the blocks on and off...

 

I'm struggling to work out how to call the blocks - can YOU help!

 

Paul

 

'Iterate through the sketches collection
'Turn the edging indicators On And Off
For Each oSketch In oDoc.ComponentDefinition.Sketches
  
Select Case  oSketch.Name

	Case "Front Edged"
	If E01 = True Then
	oSketch.Visible = True
	Else oSketch.Visible = False
	End If
	
	Case "Top Edged"
	If E02 = True Then
	oSketch.Visible = True
	Else oSketch.Visible = False
	End If
	
	Case "Back Edged"
	If E03 = True Then
	oSketch.Visible = True
	Else oSketch.Visible = False
	End If
	
	Case "Base Edged"
	If E04 = True Then
	oSketch.Visible = True
	Else oSketch.Visible = False
	End If
	
End Select
	
Next

 


Customer Adoption Specialist: Autodesk Informed Design
Help | Learn | Forum | Blog | Ideas | Sample content | Linkedin 

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

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Paul,

 

Here's a quick example:

 

Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

Dim oSketch As PlanarSketch
oSketch = oSketches.Item("Sketch2")

Dim MyArrayList As New ArrayList
MyArrayList.add("Back Edged")
MyArrayList.add("Base Edged")
MyArrayList.add("Front Edged")
MyArrayList.add("Top Edged")
MyArrayList.add("Turn ON all blocks")
MyArrayList.add("Turn OFF all blocks")

myBlock = InputListBox("Select a block to turn ON", _
MyArrayList, MyArrayList.item(0),"iLogic", "Sketch Block Names")

Dim oSketchBlock As SketchBlock
For Each oSketchBlock  In oSketch.SketchBlocks
    'get position of colon, example: MyBlock:2 returns 8
    iPos = InStr(oSketchBlock.Name, ":")
    'get block name, example: MyBlock:2 returns MyBlock
    sBlockName = Left(oSketchBlock.Name, iPos -1)

    If myBlock = "Turn ON all blocks" Then
    oSketchBlock.Visible = True
    Else If myBlock = "Turn OFF all blocks" Then
    oSketchBlock.Visible = False
    Else If myBlock = sBlockName Then
    oSketchBlock.Visible = True
    End If
    'if any sketch block is visible make the sketch visible
    If oSketchBlock.Visible = true Then oSketch.Visible = True
Next

 I hope this helps,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 4

PaulMunford
Community Manager
Community Manager

Yay!

 

Great stuff Curtis. Thanks for your help 🙂


Customer Adoption Specialist: Autodesk Informed Design
Help | Learn | Forum | Blog | Ideas | Sample content | Linkedin 

0 Likes
Message 4 of 4

RoyWickrama_RWEI
Advisor
Advisor

Hi Curtis;

 

Thanks for the posting.

I am using a test version of the coding to make vsible the blocks in my sketch (Sketch12) visible. There are a few blocks. However, while the Sketch12 is not visible, the blocks in the sketch don't turn on (not visible). Could you help me, please.

 

Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

Dim oSketch As PlanarSketch
oSketch = oSketches.Item("Sketch12")

Dim oSketchBlock As SketchBlock
For Each oSketchBlock  In oSketch.SketchBlocks
    'get position of colon, example: MyBlock:2 returns 8
    iPos = InStr(oSketchBlock.Name, ":")
    'get block name, example: MyBlock:2 returns MyBlock
    sBlockName = Left(oSketchBlock.Name, iPos-1)
 oSketchBlock.Visible = True
'    If oSketchBlock.Visible = True Then oSketch.Visible = True
Next

 

Thanks.

0 Likes