iLogic sheet scale

iLogic sheet scale

Anonymous
Not applicable
2,666 Views
17 Replies
Message 1 of 18

iLogic sheet scale

Anonymous
Not applicable

Hello -

    I am trying to create a rule to place the drawing scale on each sheet that will be derived from the lowest numbered view on that sheet.  My main goal is to be invisible to the user, in other words, to keep the user from needing to do anything regarding this function.

    I am running into 2 separate issues. 

1.  how to identify view names on each sheet.

2.  how to extract the number from the view name.

 

    Is there anyone who can help with this?  I would be extremely grateful.  When I am done, I could even share the code.  My intent is to create a different title block for each sheet from 1 to 9.  (I am hoping anyone using more than 9 sheets doesn't ever work for us, but I have seen 4 sheets used.)  (I am also thinking that 9 is a safe number without being too overdone.)  Then to create a custom property and link it to the scale for each title block.

 

    The only other way I can figure out to do this is to ask the user to name the controlling view on each sheet specially, (view3 for sheet3, etc.) and use that name to link to the scale.  However, I would really like to make this invisible and not rely on users to "not make mistakes".

 

Thank you,

SmokyRick

 

0 Likes
2,667 Views
17 Replies
Replies (17)
Message 2 of 18

jletcher
Advisor
Advisor

I am lost here. I do not follow what you are trying to do.

 

1st Inventor will put the scale in title block on the 1st view created if set up.  So I really don't see what you are asking for. Can you make it clear to us.

0 Likes
Message 3 of 18

Anonymous
Not applicable

I want to be able to put the scale on each sheet individually per the views on that sheet.  The problem is not that, as I can do that much.  The problem is how to extract the number of the view from the view names on each sheet, so that I can use the scale from the base view on each sheet for the title block on that sheet.

 

Thanks, SmokyRick

0 Likes
Message 4 of 18

jletcher
Advisor
Advisor
0 Likes
Message 5 of 18

jletcher
Advisor
Advisor

Found this too

 

 

Dim odrawdoc As DrawingDocument odrawdoc = ThisApplication.ActiveDocument customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties") For i = 1 To odrawdoc.Sheets.Count ' Make sure the desired property exists Try       prop = customPropertySet.Item("Scale" + Str(i)) Catch       ' Assume error means not found       customPropertySet.Add("", "Scale" + Str(i)) End Try Try iProperties.Value("Custom", "Scale" + Str(i)) = odrawdoc.sheets.item(i).DrawingViews.Item(1).ScaleString Catch End Try Next i InventorVb.DocumentUpdate()

0 Likes
Message 6 of 18

Anonymous
Not applicable

Thank you, but none of these tell me how to extract the view number from the view name on each sheet so I can use it as I want.

I have looked and can not seem to find this information.

SmokyRick

P.S.  Does anyone know of a good book on iLogic coding?

0 Likes
Message 7 of 18

jletcher
Advisor
Advisor

I wish there was a book...........

0 Likes
Message 8 of 18

jdkriek
Advisor
Advisor

So you are saying that the first view on each sheet isn't your base view?

Normally you would simply reiterate through all the sheets using DrawingViews.Item(1) (usually the base view) and extract the scale from that view into your title block  - pretty much exactly what the code jletcher posted does.

 

If the first view on each sheet is not the base view, then you would need to get more creative:

 

Dim baseView As DrawingView = Nothing
For Each view As DrawingView In ActiveSheet.Sheet.DrawingViews
  If (view.ParentView Is Nothing) Then
	baseView = view
	Exit For
  End If
Next

If (baseView Is Nothing) Then Return
' ... do something with baseView ...

 

Since the first view on each sheet in my drawings IS the base view - this below visually shows me what scale the base is for each sheet.

 

Dim oApp As Application: oApp = ThisApplication
Dim oDoc As DrawingDocument: oDoc = oApp.ActiveDocument
Dim oSheet As Sheet: oSheet = oDoc.ActiveSheet
Dim oSheets As Sheets: oSheets = oDoc.Sheets
Dim oView As DrawingView
For Each oSheet In oSheets
	'oSheet.Activate
	oView = oSheet.DrawingViews.Item(1)
	MsgBox(oView.ScaleString & " " & oView.Name & " " & oSheet.Name)
Next oSheet

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 9 of 18

Anonymous
Not applicable

I am sorry for being so dense.  Sometimes...   But it is difficult for me to follow the code jletcher posted.  How do you place the code in such a nice box like yours is?  And do you have only one title block?  What do you have on the title block in the place for a scale?  I think you both are so far over my head that I just didn't follow what was going on under my nose.

 

I am attaching a jpg of what code I have so far.  It sounds like you are doing what I need to do, and I am just not understanding the code enough to realise it.

 

Thanks  SmokyRick

 

revision:  Yes, the first view on each sheet can be considered to be the base view.  Although I can not say that for sure.  Many times a section (or other derived) view from sheet one may be what is first on sheet 2, etc.

r2:  I have gone and created 9 title blocks to have one for each sheet so I could make a scale1, scale2, etc for each sheet to be able to have something different on each sheet.  Do you do this differently?  I am trying to make sense of the code, but I am a bit slow at it I am afraid.

 

Thanks again.

0 Likes
Message 10 of 18

jletcher
Advisor
Advisor
Dim strScale As String = ActiveSheet.View("VIEW1").ScaleString
iProperties.Value("Summary", "Keywords") = strScale


'Forces update after rule runs 
iLogicVb.UpdateWhenDone = True
'Extracts scale from 'View 1' on drawing sheet' to a field named SCALE
SCALE = ActiveSheet.View("VIEW1").Scale
 'Writes scale to a custom iProperty named SCALE
iProperties.Value("Custom", "SCALE") = SCALE


Dim odrawdoc As DrawingDocument
odrawdoc = ThisApplication.ActiveDocument
customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties")
For i = 1 To odrawdoc.Sheets.Count
' Make sure the desired property exists
Try
      prop = customPropertySet.Item("Scale" + Str(i))
Catch
      ' Assume error means not found
      customPropertySet.Add("", "Scale" + Str(i))
End Try
Try
iProperties.Value("Custom", "Scale" + Str(i)) = odrawdoc.sheets.item(i).DrawingViews.Item(1).ScaleString
Catch
End Try
Next i
InventorVb.DocumentUpdate()

 

 Here ya go

Message 11 of 18

Anonymous
Not applicable

You guys have both given really nice replies.  With considerable code in them.  I am currently trying to make sense of the code and figure out exactly what it does.  I can see that I need more experience with Visual Basic.  (I have had none at all.)  I will figure this out and use what you have given me.  Will re-post when I get it all figured out.

 

Thank you so much,

SmokyRick

0 Likes
Message 12 of 18

Anonymous
Not applicable

Hello Guys -

    Here I am back again.  I brought the code together and think I have a working program.  Until I tried it out.  Some pages save and some don't (with no apparent reason).  I am posting my code here:

 

'	set title block & scale on each sheet of drawing
'
Dim shtNum As Integer = 1
For Each shtX As sheet In ThisDrawing.Document.Sheets
	ActiveSheet = ThisDrawing.Sheet("Sheet:" & shtNum)
	If ActiveSheet.Size = "A" Then
		ActiveSheet.TitleBlock = "FNS" & shtNum & "_A"
	Else
		ActiveSheet.TitleBlock = "FNS" & shtNum & "_Large"
	End If
	For i = 1 To 100
		Try
			SCALE = ActiveSheet.View("VIEW" & i).ScaleString
			If SCALE <> iProperties.Value("Custom","SCALE" & i) Then
				SCALE = ActiveSheet.View("VIEW" & i).ScaleString
				iProperties.Value("Custom","SCALE" & shtNum) = SCALE
				i = 101
			End If
		Catch
		End Try
	Next i
	shtNum = shtNum + 1
Next
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
InventorVb.DocumentUpdate()

 

Please look it over and tell me if I have done something stupid.

 

Thank you so much,  SmokyRick

 

P.S.  The drawing saves, but only some sheets will actually get a scale put on them.  From a 9 sheet drawing, sheets 1, 2, 3, and 6 got scale.  All pages had independent views except sheet 6 which had a view from sheet 1.

Thanks again,  Smoky

0 Likes
Message 13 of 18

Anonymous
Not applicable

I thought I should attach the sample part and drawing for this question.  In case anyone really wanted to look at what is going on, this might make it easier.

T.I.A., Smoky

0 Likes
Message 14 of 18

Anonymous
Not applicable

Here is the final code:

 

'
'	dwgSetup
'
Dim odrawdoc As DrawingDocument
odrawdoc = ThisApplication.ActiveDocument
customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties")
'
'	save date & time for plotting
'
Try
	Dim saveNow As Date
	saveNow = Now
	iProperties.Value("Custom", "saveDate") = saveNow
	iProperties.Value("Custom", "saveTime") = Now.ToString("HH:mm:ss")
Catch
End Try
'
'	set title block & scale on each sheet of drawing
'
Dim shtNum As Integer = 1
For Each shtX As sheet In ThisDrawing.Document.Sheets
	Try
		ActiveSheet = ThisDrawing.Sheet("Sheet:" & shtNum)
		If ActiveSheet.Size = "A" Then
			ActiveSheet.TitleBlock = "FNS" & shtNum & "_A"
		Else
			ActiveSheet.TitleBlock = "FNS" & shtNum & "_Large"
		End If
		Dim baseview As DrawingView = Nothing
		Try
			For Each viewX As DrawingView In ActiveSheet.Sheet.DrawingViews
				If (baseview Is Nothing) Then
					nameX = viewX.Name
					SCALE = ActiveSheet.View(nameX).ScaleString
					iProperties.Value("Custom","SCALE" & shtNum) = SCALE
					Exit For
				End If
			Next
		Catch
		End Try
		shtNum = shtNum + 1
	Catch
	End Try
Next
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
InventorVb.DocumentUpdate()

 

This works for us.  It will operate when a save is indicated, and will set the title block, as well as setting the scale to the first view in each sheet.  In order to make it work, we created separate A and Large size title blocks, then copied them to be named FNS1_A, FNS2_A, ... FNS9_A and FNS1_Large, FNS2_Large ... FNS9_Large.  I also created a group of 9 custom properties, named SCALE1, SCALE2 ... to SCALE9.  Any more than 9 sheets will put title block #1 on the further sheets, with SCALE1 in it's place in the title block.

 

We also have a place on our drawings where we have the latest save time and date.  Then, if you save before plotting, you have the time of plotting on the drawing when it goes to the shop.  This saves questions as to which one is latest.

 

jletcher and Jonathan Kriek, you were both quite helpful in attaching code for me to learn from, Thank you both.

SmokyRick

 

0 Likes
Message 15 of 18

Anonymous
Not applicable

Hi SmokeyRick, Im trying to use your code, i dont really have practice in Ilogic either...

So i dont really understand why or where did you create A and Large sized things... if you could make a screenshot of your tittle blocks, or explain that to me, id appreciate it. I already created the 9 custom scales.

In the last couple of days i was trying to adjust this scale thing with multiple sheets and didnt succeed, so i would really appreciate if you could help, and my firm. 

 

Take Care,

Gyüre Bálint

0 Likes
Message 16 of 18

Anonymous
Not applicable

Here is a pair of screen shots with our 2 title blocks.  I think you can see that we simply couldn't fit the large format one onto an A size drawing, especially since we use the A size as a portrait direction.  So we simply created 2 different blocks and saved them as such.  If you can put the question into words I would be glad to help as I can.  I have a heck of a time getting things into words others will understand, but I like the saying  "a question formed is a question half answered".

0 Likes
Message 17 of 18

Anonymous
Not applicable

Hi smokey

So i was in a hurry last time, since then i played with ilogic a bit in my designs. but i still dont know how to get that scale Rule done. So we only have one type oftitle block, we use that for all kinda papers. My problem is when there s a file with multiple sheets and run the rule i only get the VIEW1 scale on every sheet. So could you help me get that code which actually does all of the sheets? On one sheet there is usually only one scale is used (ecxept for enlarging parts, but thats is shown on the drawing) so basically getting the base view's scale would be perfect, but that can differ on eeach sheet. 

Thank you for the quick answer last time by the way.

I hope you can help me.

 

Gyüre Bálint

0 Likes
Message 18 of 18

Anonymous
Not applicable

I just tried with ours and can get a drawing scale from any drawing that has a view in it.  All different scales per what views are on that sheet.  Perhaps you removed some of the code since you are only dealing with one title block and removed the part that sets the scale on the block.  I think the part of the code that does that is :

 

For Each viewX As DrawingView In ActiveSheet.Sheet.DrawingViews
	If (baseview Is Nothing) Then
		nameX = viewX.Name
		SCALE = ActiveSheet.View(nameX).ScaleString
		iProperties.Value("Custom","SCALE" & shtNum) = SCALE
		Exit For
	End If
Next

 If that is removed, the scale will not be set.  If you are not doing this, please post what you have so we can work out what is happening.

 

Smoky Rick Crawford

0 Likes