Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic code to turn sketch block visibility on and off

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
PaulMunford
1532 Views, 3 Replies

iLogic code to turn sketch block visibility on and off

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

 

 


Autodesk Industry Marketing Manager UK D&M
Opinions are my own and may not reflect those of my company.
Linkedin Twitter Instagram Facebook Pinterest

3 REPLIES 3
Message 2 of 4

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

Message 3 of 4

Yay!

 

Great stuff Curtis. Thanks for your help 🙂

 


Autodesk Industry Marketing Manager UK D&M
Opinions are my own and may not reflect those of my company.
Linkedin Twitter Instagram Facebook Pinterest

Message 4 of 4

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report