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: 

Issue with Loop for checking view size against box2d.

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
J_Pfeifer_
780 Views, 14 Replies

Issue with Loop for checking view size against box2d.

J_Pfeifer_
Advocate
Advocate

Good morning, 

 

Got an interesting one here. Basically I have a set drawing template that i'm creating that sets up the basic views and what not for the draftsmen. I created a box2d object that represents the area in which I wish these 4 first views get placed. 

 

From there I passed a bunch of equations for placement and scaling. However My loop checks the view size width and the view size height against the values created from the box2d equations. However no matter how i set this loop up. The scale will only apply to 3 iterations. After it will enter an endless state, even though the returned values in a message box show that we should be rescaling. 

Dim oPage1Box As Box2d = oTG.CreateBox2d()
	oPage1Box.MinPoint = Box1Point
	oPage1Box.MaxPoint = Box2Point
	
	Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
	Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y
	

	'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object
	
	Dim oBox1YHeight As Double = oPage1BoxHeight /2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
	Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
	Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 
	
	'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 
	
	'Below establishes the point objects that each view on page one will be attached to upon runtime. 
	Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
	Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
	Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
	Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)
	
	'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
	'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 
	
	Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091
	Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 
	
	'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
	
	Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight 
		'
				MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
			
				oPageOneView1.Scale = oPageOneView1.Scale * .96
				oPageOneView2.Scale = oPageOneView1.Scale 
				oPageOneView3.Scale = oPageOneView1.Scale 
				oPageOneView4.Scale = oPageOneView1.Scale 
			
				oPage1.Update
				oDoc.Update
	
		'End If 
				
	Loop

 

The Rescaling of the view objects will always fail to be applied upon the thirds iteration. Then because the scale isn't being reduced the while loop will always enter giving me an endless state. I wanted this loop to remove 4-5% of the view scale per iteration until the size is under the maximums set by my box2d object. 

 

Is there some kind of limitation to the number of scales you can apply? I've even changed the loop to have an iIndex that goes up to 5. No matter what It will fail to scale at the third iteration. 

 

Placing first Loop in this text, the other iterations messagebox will be in the attachments

First loop.png

 

@A.Acheson 

@Curtis_Waguespack 

0 Likes

Issue with Loop for checking view size against box2d.

Good morning, 

 

Got an interesting one here. Basically I have a set drawing template that i'm creating that sets up the basic views and what not for the draftsmen. I created a box2d object that represents the area in which I wish these 4 first views get placed. 

 

From there I passed a bunch of equations for placement and scaling. However My loop checks the view size width and the view size height against the values created from the box2d equations. However no matter how i set this loop up. The scale will only apply to 3 iterations. After it will enter an endless state, even though the returned values in a message box show that we should be rescaling. 

Dim oPage1Box As Box2d = oTG.CreateBox2d()
	oPage1Box.MinPoint = Box1Point
	oPage1Box.MaxPoint = Box2Point
	
	Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
	Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y
	

	'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object
	
	Dim oBox1YHeight As Double = oPage1BoxHeight /2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
	Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
	Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 
	
	'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 
	
	'Below establishes the point objects that each view on page one will be attached to upon runtime. 
	Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
	Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
	Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
	Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)
	
	'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
	'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 
	
	Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091
	Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 
	
	'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
	
	Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight 
		'
				MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
			
				oPageOneView1.Scale = oPageOneView1.Scale * .96
				oPageOneView2.Scale = oPageOneView1.Scale 
				oPageOneView3.Scale = oPageOneView1.Scale 
				oPageOneView4.Scale = oPageOneView1.Scale 
			
				oPage1.Update
				oDoc.Update
	
		'End If 
				
	Loop

 

The Rescaling of the view objects will always fail to be applied upon the thirds iteration. Then because the scale isn't being reduced the while loop will always enter giving me an endless state. I wanted this loop to remove 4-5% of the view scale per iteration until the size is under the maximums set by my box2d object. 

 

Is there some kind of limitation to the number of scales you can apply? I've even changed the loop to have an iIndex that goes up to 5. No matter what It will fail to scale at the third iteration. 

 

Placing first Loop in this text, the other iterations messagebox will be in the attachments

First loop.png

 

@A.Acheson 

@Curtis_Waguespack 

14 REPLIES 14
Message 2 of 15
WCrihfield
in reply to: J_Pfeifer_

WCrihfield
Mentor
Mentor

Hi @J_Pfeifer_.  Just making a couple comments, and dropping a couple links in here to some previous forum discussions I have been involved with that you may find interesting or useful.  You may want to approach or figure out the proper scale factor in another way, instead of using a large loop of scaling change attempts after the view has already been created.  It may be better to obtain the main size dimensions of the model, then the available space within the sheet for views, then compare those two sizes (with orientation / rotation of the model and sheet orientation in mind), then calculate an initial scale based on those size differences.  Below are a couple links which contain some code for creating multiple drawing views of a model on a sheet, and they include code for figuring out scale and orientation of the views.  Just some food for thought, and another angle for looking at the task / challenge.

 

https://forums.autodesk.com/t5/inventor-programming-ilogic/automaticly-create-a-drawing-from-a-part/... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-create-drawnings-of-all-parts-from... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Hi @J_Pfeifer_.  Just making a couple comments, and dropping a couple links in here to some previous forum discussions I have been involved with that you may find interesting or useful.  You may want to approach or figure out the proper scale factor in another way, instead of using a large loop of scaling change attempts after the view has already been created.  It may be better to obtain the main size dimensions of the model, then the available space within the sheet for views, then compare those two sizes (with orientation / rotation of the model and sheet orientation in mind), then calculate an initial scale based on those size differences.  Below are a couple links which contain some code for creating multiple drawing views of a model on a sheet, and they include code for figuring out scale and orientation of the views.  Just some food for thought, and another angle for looking at the task / challenge.

 

https://forums.autodesk.com/t5/inventor-programming-ilogic/automaticly-create-a-drawing-from-a-part/... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-create-drawnings-of-all-parts-from... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 15

Curtis_Waguespack
Consultant
Consultant

@J_Pfeifer_ 

 

This worked for me after doing a bit of set up to complete the code you provided.

 

See the attached 2023 example files. 

 

Note I added an endless loop killer trick that I picked up from someone on this forum. Basically the loop with quit if it doesn't find the text file it expects to find. I just rename the file to get out of the endless loop as needed.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

oPageOneView1 = ActiveSheet.View("VIEW1")
oPageOneView2 = ActiveSheet.View("VIEW2")
oPageOneView3 = ActiveSheet.View("VIEW3")
oPageOneView4 = ActiveSheet.View("VIEW4")

oPageOneView1.Scale = 1
oPageOneView2.Scale = oPageOneView1.Scale
oPageOneView3.Scale = oPageOneView1.Scale
oPageOneView4.Scale = oPageOneView1.Scale

msgbox("Scale reset for testing", , "iLogic")

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim Box1Point As Point2d = oTG.CreatePoint2d(0, 0)
Dim Box2Point As Point2d = oTG.CreatePoint2d(5, 5)

Dim oPage1Box As Box2d = oTG.CreateBox2d()
oPage1Box.MinPoint = Box1Point
oPage1Box.MaxPoint = Box2Point

Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y


'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object

Dim oBox1YHeight As Double = oPage1BoxHeight / 2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 

'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 

'Below establishes the point objects that each view on page one will be attached to upon runtime. 
Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)

'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 

Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091
Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 

'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

i = 0
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	'
	'MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: " & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

	oPageOneView1.Scale = oPageOneView1.Scale * .96
	oPageOneView2.Scale = oPageOneView1.Scale
	oPageOneView3.Scale = oPageOneView1.Scale
	oPageOneView4.Scale = oPageOneView1.Scale

	ActiveSheet.NativeEntity.Update
	ThisDoc.Document.Update

	'endless loop killer just in case
	oFile = "C:\Temp\Endless Loop Saftey File.txt"
	If IO.File.Exists("C:\Temp\Endless Loop Saftey File.txt") = False Then
		MsgBox("The rule called '" & iLogicVb.RuleName & "' stopped because text file doesn't exist:" & vbLf & oFile, , "iLogic")
		Exit Sub
	End If
	i = i + 1
Loop

MsgBox(i & " loops were run")

 

0 Likes

@J_Pfeifer_ 

 

This worked for me after doing a bit of set up to complete the code you provided.

 

See the attached 2023 example files. 

 

Note I added an endless loop killer trick that I picked up from someone on this forum. Basically the loop with quit if it doesn't find the text file it expects to find. I just rename the file to get out of the endless loop as needed.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

oPageOneView1 = ActiveSheet.View("VIEW1")
oPageOneView2 = ActiveSheet.View("VIEW2")
oPageOneView3 = ActiveSheet.View("VIEW3")
oPageOneView4 = ActiveSheet.View("VIEW4")

oPageOneView1.Scale = 1
oPageOneView2.Scale = oPageOneView1.Scale
oPageOneView3.Scale = oPageOneView1.Scale
oPageOneView4.Scale = oPageOneView1.Scale

msgbox("Scale reset for testing", , "iLogic")

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim Box1Point As Point2d = oTG.CreatePoint2d(0, 0)
Dim Box2Point As Point2d = oTG.CreatePoint2d(5, 5)

Dim oPage1Box As Box2d = oTG.CreateBox2d()
oPage1Box.MinPoint = Box1Point
oPage1Box.MaxPoint = Box2Point

Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y


'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object

Dim oBox1YHeight As Double = oPage1BoxHeight / 2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 

'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 

'Below establishes the point objects that each view on page one will be attached to upon runtime. 
Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)

'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 

Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091
Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 

'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

i = 0
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	'
	'MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: " & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

	oPageOneView1.Scale = oPageOneView1.Scale * .96
	oPageOneView2.Scale = oPageOneView1.Scale
	oPageOneView3.Scale = oPageOneView1.Scale
	oPageOneView4.Scale = oPageOneView1.Scale

	ActiveSheet.NativeEntity.Update
	ThisDoc.Document.Update

	'endless loop killer just in case
	oFile = "C:\Temp\Endless Loop Saftey File.txt"
	If IO.File.Exists("C:\Temp\Endless Loop Saftey File.txt") = False Then
		MsgBox("The rule called '" & iLogicVb.RuleName & "' stopped because text file doesn't exist:" & vbLf & oFile, , "iLogic")
		Exit Sub
	End If
	i = i + 1
Loop

MsgBox(i & " loops were run")

 

Message 4 of 15

J_Pfeifer_
Advocate
Advocate

I'm pretty sure that I'll need to rethink my approach like stated by WCrihfield. I was able to pull your parts in Curtis_Waguespack. Using your simple square I was able to get it to scale down to the proper size. 

 

It seems when I use the small square part, everything functions as normal. When I attempt to pull my own object in using your code it has the same effect eventually. It iterates down to a certain scale then sits in an infinite loop. Inside my own drawing, running my own code = .02 / 1 scale. Inside a custom drawing with your code = .2 / 1 scale.

 

Even verifying that you're part was able to iterate 12 times before hitting the proper size. Either of the codes using an in house model will be reduced by more than three iterations now. Yet still will reach a point where an endless loop is entered. 

 

When I asked this question I figured I'd done something dumb with my loop to create this problem (When working with this I still cannot fathom why I'm entering a endless loop, the values should not be passing into an endless state) . Now, I'm just getting lost in the sauce. From my perspective I need to get away from using these view sizes. It's having really inconsistent results. Thanks for the endless loop bypass. what a useful little file. 

 

 

I'm pretty sure that I'll need to rethink my approach like stated by WCrihfield. I was able to pull your parts in Curtis_Waguespack. Using your simple square I was able to get it to scale down to the proper size. 

 

It seems when I use the small square part, everything functions as normal. When I attempt to pull my own object in using your code it has the same effect eventually. It iterates down to a certain scale then sits in an infinite loop. Inside my own drawing, running my own code = .02 / 1 scale. Inside a custom drawing with your code = .2 / 1 scale.

 

Even verifying that you're part was able to iterate 12 times before hitting the proper size. Either of the codes using an in house model will be reduced by more than three iterations now. Yet still will reach a point where an endless loop is entered. 

 

When I asked this question I figured I'd done something dumb with my loop to create this problem (When working with this I still cannot fathom why I'm entering a endless loop, the values should not be passing into an endless state) . Now, I'm just getting lost in the sauce. From my perspective I need to get away from using these view sizes. It's having really inconsistent results. Thanks for the endless loop bypass. what a useful little file. 

 

 

Message 5 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor

What size is your part?

It looks like at some point iLogic cannot update return oPageOneView1.Width and oPageOneView1.Height fast enough.

Scale is going down but oPageOneView1.Width and oPageOneView1.Height stay at same value for a while.

Loop 90 to 103, the numbers are Scale, Width, Height:

INFO|Loop 90-0.0243602761172251
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 91-0.0233858650725361
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 92-0.0224504304696347
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 93-0.0215524132508493
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 94-0.0206903167208153
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 95-0.0198627040519827
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 96-0.0190681958899034
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 97-0.0183054680543073
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 98-0.017573249332135
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 99-0.0168703193588496
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 100-0.0161955065844956
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 101-0.0155476863211158
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 102-0.0149257788682711
INFO|   1.17525817860403
INFO|   0.0578375124032558

 

What size is your part?

It looks like at some point iLogic cannot update return oPageOneView1.Width and oPageOneView1.Height fast enough.

Scale is going down but oPageOneView1.Width and oPageOneView1.Height stay at same value for a while.

Loop 90 to 103, the numbers are Scale, Width, Height:

INFO|Loop 90-0.0243602761172251
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 91-0.0233858650725361
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 92-0.0224504304696347
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 93-0.0215524132508493
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 94-0.0206903167208153
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 95-0.0198627040519827
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 96-0.0190681958899034
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 97-0.0183054680543073
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 98-0.017573249332135
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 99-0.0168703193588496
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 100-0.0161955065844956
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 101-0.0155476863211158
INFO|   1.91813197773426
INFO|   0.0943962646446432
INFO|Loop 102-0.0149257788682711
INFO|   1.17525817860403
INFO|   0.0578375124032558

 

Message 6 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor

I think view scale is rounded up.  So at some point it won't change.

0 Likes

I think view scale is rounded up.  So at some point it won't change.

Message 7 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor
Accepted solution

The problem is:

oPageOneView1.Scale = oPageOneView1.Scale * 0.96

After enough loop, the result stop changing.

 

Change the code to:

oScale = oPageOneView1.Scale
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	
	oScale = oScale * 0.96
	oPageOneView1.Scale = oScale
	oPageOneView2.Scale = oScale
	oPageOneView3.Scale = oScale
	oPageOneView4.Scale = oScale

 

and it won't get stuck.

The problem is:

oPageOneView1.Scale = oPageOneView1.Scale * 0.96

After enough loop, the result stop changing.

 

Change the code to:

oScale = oPageOneView1.Scale
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	
	oScale = oScale * 0.96
	oPageOneView1.Scale = oScale
	oPageOneView2.Scale = oScale
	oPageOneView3.Scale = oScale
	oPageOneView4.Scale = oScale

 

and it won't get stuck.

Message 8 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor
Dim oScale As Double = 1.0

oPageOneView1 = ActiveSheet.View("VIEW1")
oPageOneView2 = ActiveSheet.View("VIEW2")
oPageOneView3 = ActiveSheet.View("VIEW3")
oPageOneView4 = ActiveSheet.View("VIEW4")

oPageOneView1.Scale = oScale
oPageOneView2.Scale = oScale
oPageOneView3.Scale = oScale
oPageOneView4.Scale = oScale

msgbox("Scale reset for testing", , "iLogic")

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim Box1Point As Point2d = oTG.CreatePoint2d(0, 0)
Dim Box2Point As Point2d = oTG.CreatePoint2d(5, 5)

Dim oPage1Box As Box2d = oTG.CreateBox2d()
oPage1Box.MinPoint = Box1Point
oPage1Box.MaxPoint = Box2Point

Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y


'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object

Dim oBox1YHeight As Double = oPage1BoxHeight / 2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 

'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 

'Below establishes the point objects that each view on page one will be attached to upon runtime. 
Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)

'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 

Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091

Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 
Logger.Info("MaxWidth: " & Page1MaxViewWidth)
Logger.Info("MaxHeight: " & Page1MaxViewHeight)

Logger.Info("View Width: " & oPageOneView1.Width)
Logger.Info("View Height: " & oPageOneView1.Height)

'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

i = 0
oScale = oPageOneView1.Scale
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	'
	'MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: " & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
	oScale = oScale * 0.96
	oPageOneView1.Scale = oScale
	oPageOneView2.Scale = oScale
	oPageOneView3.Scale = oScale
	oPageOneView4.Scale = oScale
	
	Logger.Info("Loop " & i & " - oScale:" & oScale & " Viewscale: " & oPageOneView1.Scale)
	Logger.Info("   " & oPageOneView1.Width)
	Logger.Info("   " & oPageOneView1.Height)
	Logger.Info("   View Width: " & oPageOneView1.Width)
	Logger.Info("   View Height: " & oPageOneView1.Height)

	ActiveSheet.NativeEntity.Update
	ThisDoc.Document.Update

	'endless loop killer just in case
	oFile = "C:\Temp\Endless Loop Saftey File.txt"
	If IO.File.Exists("C:\Temp\Endless Loop Saftey File.txt") = False Then
		MsgBox("The rule called '" & iLogicVb.RuleName & "' stopped because text file doesn't exist:" & vbLf & oFile, , "iLogic")
		Exit Sub
	End If
	i = i + 1
Loop
Logger.Info("Width: " & (oPageOneView1.Width / Page1MaxViewWidth))
Logger.Info("Height: " & (oPageOneView1.Height / Page1MaxViewHeight))
MsgBox(i & " loops were run")

Dim oScale As Double = 1.0

oPageOneView1 = ActiveSheet.View("VIEW1")
oPageOneView2 = ActiveSheet.View("VIEW2")
oPageOneView3 = ActiveSheet.View("VIEW3")
oPageOneView4 = ActiveSheet.View("VIEW4")

oPageOneView1.Scale = oScale
oPageOneView2.Scale = oScale
oPageOneView3.Scale = oScale
oPageOneView4.Scale = oScale

msgbox("Scale reset for testing", , "iLogic")

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim Box1Point As Point2d = oTG.CreatePoint2d(0, 0)
Dim Box2Point As Point2d = oTG.CreatePoint2d(5, 5)

Dim oPage1Box As Box2d = oTG.CreateBox2d()
oPage1Box.MinPoint = Box1Point
oPage1Box.MaxPoint = Box2Point

Dim oPage1BoxWidth As Double = Box2Point.X - Box1Point.X
Dim oPage1BoxHeight As Double = Box2Point.Y - Box1Point.Y


'MessageBox.Show(oPage1BoxWidth.ToString & " " & oPage1BoxHeight.ToString) 'This checks the size of the x and y of the box object

Dim oBox1YHeight As Double = oPage1BoxHeight / 2 + .635 'This variable represents the distance from center to bottom of page for page one view placement
Dim oBox1XWidthStart As Double = (oPage1BoxWidth / 4) / 2 + .635 'This variable represents the distance from left edge of sheet to center start point for first page 1st view placement
Dim oBox1XWidthCenter As Double = (oPage1BoxWidth / 4) / 2 'This value represents the distance on the x axis for view spacing. 

'Messagebox.Show("The first value should match 6.945 " & oBox1Yheight.ToString & " This second value should match 4.68 " & oBox1XWidthStart.ToString & " The thrid value should match 4.0456 " & oBox1XWidthCenter.ToString) 'This verifies the correct distance values mathmatically. 

'Below establishes the point objects that each view on page one will be attached to upon runtime. 
Dim PageOneViewOne As Point2d = oTG.CreatePoint2d(oBox1XWidthStart, oBox1YHeight)
Dim PageOneViewTwo As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 2, oBox1YHeight)
Dim PageOneViewThree As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 4, oBox1YHeight)
Dim PageOneviewFour As Point2d = oTG.CreatePoint2d(oBox1XWidthStart + oBox1XWidthCenter * 6, oBox1YHeight)

'Start the scaling of each view in sheet one to be smaller than the quadrant of the bounding box. 
'Using height, and width of the views, we can compare that to a variable established to represent the size of the quadrant they're within. 

Dim Page1MaxViewWidth As Double = oPage1BoxWidth / 4 ' Should equal 8.091

Dim Page1MaxViewHeight As Double = oPage1BoxHeight 'Should be the same as the total height of the box, no reason to equate it. 
Logger.Info("MaxWidth: " & Page1MaxViewWidth)
Logger.Info("MaxHeight: " & Page1MaxViewHeight)

Logger.Info("View Width: " & oPageOneView1.Width)
Logger.Info("View Height: " & oPageOneView1.Height)

'MessageBox.Show("OUTSIDE LOOP - Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: "  & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)

i = 0
oScale = oPageOneView1.Scale
Do While oPageOneView1.Width > Page1MaxViewWidth Or oPageOneView1.Height > Page1MaxViewHeight
	'
	'MessageBox.Show("Page one width: " & oPageOneView1.Width.ToString & " Page one height: " & oPageOneView1.Height.ToString & vbCrLf & " Page 1 width maximum: " & Page1MaxViewWidth & " Page 1 height maximum: " & Page1MaxViewHeight)
	oScale = oScale * 0.96
	oPageOneView1.Scale = oScale
	oPageOneView2.Scale = oScale
	oPageOneView3.Scale = oScale
	oPageOneView4.Scale = oScale
	
	Logger.Info("Loop " & i & " - oScale:" & oScale & " Viewscale: " & oPageOneView1.Scale)
	Logger.Info("   " & oPageOneView1.Width)
	Logger.Info("   " & oPageOneView1.Height)
	Logger.Info("   View Width: " & oPageOneView1.Width)
	Logger.Info("   View Height: " & oPageOneView1.Height)

	ActiveSheet.NativeEntity.Update
	ThisDoc.Document.Update

	'endless loop killer just in case
	oFile = "C:\Temp\Endless Loop Saftey File.txt"
	If IO.File.Exists("C:\Temp\Endless Loop Saftey File.txt") = False Then
		MsgBox("The rule called '" & iLogicVb.RuleName & "' stopped because text file doesn't exist:" & vbLf & oFile, , "iLogic")
		Exit Sub
	End If
	i = i + 1
Loop
Logger.Info("Width: " & (oPageOneView1.Width / Page1MaxViewWidth))
Logger.Info("Height: " & (oPageOneView1.Height / Page1MaxViewHeight))
MsgBox(i & " loops were run")
Message 9 of 15
Michael.Navara
in reply to: J_Pfeifer_

Michael.Navara
Advisor
Advisor
Accepted solution

Maybe it is off topic. But if the following picture describes your needs, you can calculate view scale without this potentially endless loop

20240621-01.png

 

 

View1 Width * ScaleX + GapX + View2 Width * ScaleX = AreaWidth
ScaleX = (AreaWidth - GapX) / (View1 Width + View2 Width)

View1 Height * ScaleY + GapY + View3 Height * ScaleY = AreaHeight
ScaleY = (AreaHeight - GapY) / (View1 Height + View3 Height)

Scale = Min(ScaleX, ScaleY)

 

Maybe it is off topic. But if the following picture describes your needs, you can calculate view scale without this potentially endless loop

20240621-01.png

 

 

View1 Width * ScaleX + GapX + View2 Width * ScaleX = AreaWidth
ScaleX = (AreaWidth - GapX) / (View1 Width + View2 Width)

View1 Height * ScaleY + GapY + View3 Height * ScaleY = AreaHeight
ScaleY = (AreaHeight - GapY) / (View1 Height + View3 Height)

Scale = Min(ScaleX, ScaleY)

 

Message 10 of 15
J_Pfeifer_
in reply to: Michael.Navara

J_Pfeifer_
Advocate
Advocate

This is very very similar to what I'm trying to achieve. The only difference is the space in which my views will be placed. The first page layout has 4 views of each isometric within the sheet. All lined up next to each other. We have a bunch of informational boxes and dialog that also gets added to this sheet. So I needed to carve out the exact place that would always be the correct size for the views. 

 

You've given me another way to tackle the problem, similar thinking but different equations that will be nice to keep in the back pocket, along with this stellar graphic to reference. I've been drawing it out on paper so far :P. 

 

It looks like Fredrick was able to sort out exactly what was happening within this loop and provided a way for it to function. Going to pursue this today, running it through examples and stuff before determining the "solution". It seems many people have different ideas and paths to producing something similar along these lines. 

0 Likes

This is very very similar to what I'm trying to achieve. The only difference is the space in which my views will be placed. The first page layout has 4 views of each isometric within the sheet. All lined up next to each other. We have a bunch of informational boxes and dialog that also gets added to this sheet. So I needed to carve out the exact place that would always be the correct size for the views. 

 

You've given me another way to tackle the problem, similar thinking but different equations that will be nice to keep in the back pocket, along with this stellar graphic to reference. I've been drawing it out on paper so far :P. 

 

It looks like Fredrick was able to sort out exactly what was happening within this loop and provided a way for it to function. Going to pursue this today, running it through examples and stuff before determining the "solution". It seems many people have different ideas and paths to producing something similar along these lines. 

Message 11 of 15
J_Pfeifer_
in reply to: Frederick_Law

J_Pfeifer_
Advocate
Advocate

This seems to have fixed the issue. I'm going to be testing things further to make sure the edge cases are not going to be a problem. The size of the internal parts are huge, yet that's not really the problem overall, its more that our current operation has them open the template, select a model from the file system. Then automatically places the 4 views on the front page.  Our models themselves can be 48" tall all the way to 30+ft. That's why I needed to make changes to them after the fact, or go backwards in the code a bit and create a template that places all the views programmatically rather than a template insert. 

 

Tons of amazing information and advice on this forum, I'm happy to see it from everyone. 

This seems to have fixed the issue. I'm going to be testing things further to make sure the edge cases are not going to be a problem. The size of the internal parts are huge, yet that's not really the problem overall, its more that our current operation has them open the template, select a model from the file system. Then automatically places the 4 views on the front page.  Our models themselves can be 48" tall all the way to 30+ft. That's why I needed to make changes to them after the fact, or go backwards in the code a bit and create a template that places all the views programmatically rather than a template insert. 

 

Tons of amazing information and advice on this forum, I'm happy to see it from everyone. 

Message 12 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor

You already got:

oPageOneView1.Width, Page1MaxViewWidth

oPageOneView1.Height, Page1MaxViewHeight

 

WidthScale = Page1MaxViewWidth / oPageOneView1.Width

HeightScale = Page1MaxViewHeight / oPageOneView1.Height

 

Use the smaller one.

0 Likes

You already got:

oPageOneView1.Width, Page1MaxViewWidth

oPageOneView1.Height, Page1MaxViewHeight

 

WidthScale = Page1MaxViewWidth / oPageOneView1.Width

HeightScale = Page1MaxViewHeight / oPageOneView1.Height

 

Use the smaller one.

Message 13 of 15
Frederick_Law
in reply to: J_Pfeifer_

Frederick_Law
Mentor
Mentor

@J_Pfeifer_ wrote:

its more that our current operation has them open the template, select a model from the file system. Then automatically places the 4 views on the front page.


Fix it in Style.

Setup proper scales and IV will pick the best one when adding new view.

Your problem is you don't have enough scale in the list.

Style-Scale-03.jpg

 

I'm old school.

I don't like 1/7, 1/11, 1/111, 1/77777777, 0.169742335411869 scales.

0 Likes


@J_Pfeifer_ wrote:

its more that our current operation has them open the template, select a model from the file system. Then automatically places the 4 views on the front page.


Fix it in Style.

Setup proper scales and IV will pick the best one when adding new view.

Your problem is you don't have enough scale in the list.

Style-Scale-03.jpg

 

I'm old school.

I don't like 1/7, 1/11, 1/111, 1/77777777, 0.169742335411869 scales.

Message 14 of 15
WCrihfield
in reply to: J_Pfeifer_

WCrihfield
Mentor
Mentor

Hi @J_Pfeifer_.  Just going to throw another tip in here.  Have you considered using SheetFormats / SheetFormat ?

WCrihfield_0-1718975924363.png

When you get a drawing sheet set-up the way you want it...

  • with or without a specific border
  • with or without a specific title block
  • with or without PartsLists / Tables
  • with or without general text notes

You can save it as a SheetFormat, which can then be used to quickly create a new sheet from, with all that stuff already on it.  If the SheetFormat has views in it, they can either be set to adhere to a specific scale, or they can be set to scale them automatically for you.

To Work with Drawing Templates, Sheets, and Sheet Formats 

SheetFormat.HasDrawingViews 

SheetFormat.FitViewsToSheet 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Hi @J_Pfeifer_.  Just going to throw another tip in here.  Have you considered using SheetFormats / SheetFormat ?

WCrihfield_0-1718975924363.png

When you get a drawing sheet set-up the way you want it...

  • with or without a specific border
  • with or without a specific title block
  • with or without PartsLists / Tables
  • with or without general text notes

You can save it as a SheetFormat, which can then be used to quickly create a new sheet from, with all that stuff already on it.  If the SheetFormat has views in it, they can either be set to adhere to a specific scale, or they can be set to scale them automatically for you.

To Work with Drawing Templates, Sheets, and Sheet Formats 

SheetFormat.HasDrawingViews 

SheetFormat.FitViewsToSheet 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 15
J_Pfeifer_
in reply to: WCrihfield

J_Pfeifer_
Advocate
Advocate

Yeah, a template file with lots of stuff has already been setup for the most part. All those dialogs and informational boxes are imported on the template itself. However, as we start going to page 2, 3, 4, and so on. Depending on what the model itself requires, different boxes and information is passed. So there isn't a "one stop" template that would work given our situation. We might have something small with 20+ fittings/attachments or something huge with 5. Then depending on the actuall item attached, section views, orientations, and rotations might need to be created for each. 


This code is the start of my adventure into automating the drawing process at a higher level. I was attempting to base everything off the first views that were imported into the document from the template. I've gotten pretty far, however I'm starting to run into smaller issue with accessing the model parameters from an assembly drawing view. IE, I need to get the referenced document from a drawing view, this document will be an assembly, then I need to iterate through the Occurrences to drive out the different solids/items for further automation. 

 

More than Likely, there is an easier way to setup the most basic views and what not outside of the rule. I'm making it hard on myself intentionally to learn the ins and outs of different portions of the API using rules. The more I know the better I'll be. I appreciate everyone's help so far. Some problems are just better to be asked than searched. 

0 Likes

Yeah, a template file with lots of stuff has already been setup for the most part. All those dialogs and informational boxes are imported on the template itself. However, as we start going to page 2, 3, 4, and so on. Depending on what the model itself requires, different boxes and information is passed. So there isn't a "one stop" template that would work given our situation. We might have something small with 20+ fittings/attachments or something huge with 5. Then depending on the actuall item attached, section views, orientations, and rotations might need to be created for each. 


This code is the start of my adventure into automating the drawing process at a higher level. I was attempting to base everything off the first views that were imported into the document from the template. I've gotten pretty far, however I'm starting to run into smaller issue with accessing the model parameters from an assembly drawing view. IE, I need to get the referenced document from a drawing view, this document will be an assembly, then I need to iterate through the Occurrences to drive out the different solids/items for further automation. 

 

More than Likely, there is an easier way to setup the most basic views and what not outside of the rule. I'm making it hard on myself intentionally to learn the ins and outs of different portions of the API using rules. The more I know the better I'll be. I appreciate everyone's help so far. Some problems are just better to be asked than searched. 

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

Post to forums  

Autodesk Design & Make Report