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: 

Control 'break' size in drawing view using iLogic?

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
andrew.reynolds
5404 Views, 23 Replies

Control 'break' size in drawing view using iLogic?

Hi all,

 

Is there any way using iLogic or other method to automatically control the size of the 'break' in a drawing view? I have built a model which uses iLogic to control virtually everything, however the large variations in the length of the product mean that there are some interesting results when it comes to the broken drawing views updating.

 

Ideally, it would be nice to locate the break at the absolute center of the view and then size it as a percentage of the view size along one axis or perhaps according to some other length based rule.

 

Any ideas are greatly appreciated!

 

Cheers.

 

AndrewR

Dell Precision M6400 - C2D 2.66 / 8gb / Quadro FX3700M / Win 7 Pro x64
23 REPLIES 23
Message 2 of 24
MjDeck
in reply to: andrew.reynolds

On Inventor 2011, look at the iLogic 2011 Samples project. In the Drawings directory there is a file named BreakView.idw.  It has a rule that will adjust the width of a break in the view to maintain a constant view width.  To do it, it deletes and then recreates the break.  Here is the rule:

 

If (ActiveSheet.Name <> "Sheet:1") Then Return
Dim viewL = ActiveSheet.View("VIEW1")
Dim view = viewL.View
If (view.BreakOperations.Count > 0) Then
  view.BreakOperations(1).Delete
End If

Dim xMid As Double = ActiveSheet.Sheet.Width / 2
Dim modelDocName = IO.Path.GetFileName(viewL.ModelDocument.FullFileName)
Dim modelLength As Double = Parameter(modelDocName, "Length")
If (modelLength < 12) Then Return
Dim breakWidth As Double = (modelLength - 10) * 2.54
Dim startPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid - breakWidth/2, 0)
Dim endPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid + breakWidth/2, 0)
view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt)

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 24

Hi Mike,

 

I had looked around but the samples were the last place i had thought of... excellent advice!

 

I'm adapting the code  to suit my model, but i've got an error message appearing that says "The parameter is incorrect".

 

I know the first section that removes the break is correct as that is working, it's just not creating the new break.

 

 

ActiveSheet.View("DETAIL").SetCenter(320, 200) 'If changing center pos, remember to change break geometry below

If (ActiveSheet.Name <> "Sheet:1") Then Return
Dim viewL = ActiveSheet.View("DETAIL")
Dim view = viewL.View
If (view.BreakOperations.Count > 0) Then
view.BreakOperations(1).Delete
End If

Dim xMid As Double = 320
Dim modelLength As Double = Parameter("2BFD_MESH.iam", "BW_LEN")
If (modelLength < 500) Then Return
Dim breakWidth As Double = (modelLength - 450) / 4
Dim startPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid - breakWidth/2, 0)
Dim endPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid + breakWidth/2, 0)
view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt)

 

Cheers.

AndrewR

Dell Precision M6400 - C2D 2.66 / 8gb / Quadro FX3700M / Win 7 Pro x64
Message 4 of 24
MjDeck
in reply to: andrew.reynolds

 I think the error is caused by the breakpoint being outside of the view.  I should have mentioned that these are Inventor API calls, and all API calls require coordinates and lengths in units of cm.  But iLogic works in document units. It looks like your drawing units are mm. Here's some changes that should fix it:

 

Dim startPt = ThisApplication.TransientGeometry.CreatePoint2d((xMid - breakWidth/2) * 0.1, 0)
Dim endPt = ThisApplication.TransientGeometry.CreatePoint2d((xMid + breakWidth/2) * 0.1, 0)

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 24
andrew.reynolds
in reply to: MjDeck

As always Mike, you're right on the money.

 

It seems strange that the API requires units of centimetres when it's neither American nor metric! Oh well, live and learn...

 

For anyone interested in the add break function, there are additional parameters you can include to control the style and sizing of the symbol... For instance my line below uses the structural style symbol at 10 display size with a gap of 3mm.

 

view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt, BreakStyleEnum.kStructuralBreakStyle, 10, 0.3)

Once again, thanks for the help Mike!

AndrewR

Dell Precision M6400 - C2D 2.66 / 8gb / Quadro FX3700M / Win 7 Pro x64
Message 6 of 24

Hi Mike,

 

I have moved on to my next incarnation of this project, and the drawing now requires 2 breaks to be added to the view. I have managed to get the creation of the 2 new break lines to work fine, it's the removal of the existing breaks that is causing an issue for me. Can you please let me know what the syntax would be to clear all of the breaks on a particular view? Below is what you suggested to remove a single break, but now there is more than 1 on the view...

 

The obvious "view.BreakOperations(2).Delete" causes an error.

 

If (ActiveSheet.Name <> "Sheet:1") Then Return
Dim viewL = ActiveSheet.View("DETAIL")
Dim view = viewL.View
If (view.BreakOperations.Count > 0) Then
view.BreakOperations(1).Delete
 End If
AndrewR

Dell Precision M6400 - C2D 2.66 / 8gb / Quadro FX3700M / Win 7 Pro x64
Message 7 of 24
MjDeck
in reply to: andrew.reynolds

This will do it:

For Each breakOp In view.BreakOperations
  breakOp.Delete
Next

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 24
HvHelden
in reply to: andrew.reynolds

Hello,

 

When reading the posts in this subject, I was very apreciated. That while I was searching for doing the same rules for my assembly; with the same reason. (too large for drawing sheet).

 

When i copied the lines to my Rule in iLogic, i think i see an problem with those lines.

Especially the last 3 lines gives me errors. iLogic doesn't understand the frases.

DimstartPt=ThisApplication.TransientGeometry.CreatePoint2d(xM?id-breakWidth/2*0.1, 0)DimendPt=ThisApplication.TransientGeometry.CreatePoint2d(xM?id+breakWidth/2*0.1, 0)view.BreakOperations.Add(BreakOrientationEnum.kHor?izontalBreakOrientation, startPt, endPt)

In my iLogic, the words 'Dim' and 'ThisApplication' where known by iLogic, even the characters like /, *, + and the numbers. But words like TransientGeometry.CreatePoint2d where brown, so i think iLogic doesn't understand it, isn't it?

1 error more in the last line, kHorizontalBreakOrientation was the same problem; 'kHor' is not a member of Inventor.BreakOrientationEnum, he said.

Edit Rule Rule0_2013-02-12_15-09-05.jpg

 

I hope someone could help me with this code, I like to use this.

Thanks in advance!

 

HvHelden

 

Message 9 of 24
adam.nagy
in reply to: HvHelden

Hi,

 

The brown colour does not mean that iLogic does not understand the property - as you can see in the previously posted posts as well, which are working for others.

 

It seems that your code just has some organizational issues:

- the "0)" line should be ending the previous line instead of starting a new one

- remove the "?" question marks from the code

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 10 of 24
HvHelden
in reply to: adam.nagy

Hello!

Thanks for your reply,

 

The suggests you did weren't the problem, in my iLogic rule none ?-symbol visible, and the "0)" point is the end of an line, view.BreakOperations.Add stands on an new line.

 

I've rewrite some line's (except copy, only overwrite by myself) and errors from before were resolved!

Current problem is only the 'view' in view.BreakOperations.Add(

iLogic gives me the error: "Error on Line 49 : 'view' is ambiguous, imported from the namespaces or types 'Inventor, System.Windows.Forms'."

 

After retype the word 'view' and more, the ambiguous error occur.

MjDeck and Adrew.reynolds, dit that error in your rule even occur?

I'am very curious about the reason.

 

Thanks in advance for help!

HvHelden

 

PS: (The 'delete-break lines' work fine)

 

 

 

 

Message 11 of 24
adam.nagy
in reply to: HvHelden

Hi,

 

My guess is that your code indeed ended up with some special characters - perhaps not exactly a "?" but other ones that are not visible in the iLogic editor.

This assumption is supported by the fact that:

- when you copy pasted your code into the discussion forum, then the formatting got messed up and "?" characters appeared

- the error said "Error on Line 37: 'kHor' is not a member of 'Inventor.BreakOrientationEnum'." - i.e. there was something in between "kHor" and "izontalBreakOrientation" that prevented the iLogic interpreter from processing the complete string of "kHorizontalBreakOrientation"

- once you rewrote some of the parts they started working

 

I would suggest copying all your code from the iLogic editor into Notepad and see what you get (maybe by now you removed all the nasty special characters by rewriting things, but maybe not) If some funny characters show up or lines are broken up wrong, then correct those and then copy/paste back the code from Notepad into the iLogic editor.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 12 of 24
MjDeck
in reply to: HvHelden

HvHelden,
 To help us to resolve this error:
 "Error on Line 49 : 'view' is ambiguous, imported from the namespaces or types 'Inventor, System.Windows.Forms'."
can you post the complete text of your rule?
To avoid formatting problems, please copy and paste the text to Notepad. Then save the file as a txt file, and attach that file to your post.


Mike Deck
Software Developer
Autodesk, Inc.

Message 13 of 24
HvHelden
in reply to: MjDeck

Hello Adam and Mike,

Thank you for helping sofar.

It's a few weeks ago that i have worked on the rule, because of i had more functions than only do engineering work.

I hope you can remember my problem, and help me solve it.

In this post, i place the textfile 'Rule0' with the iLogic rule from the .idw.

 

Thanks in advance!

HvH

Sub Main
Teller=iTrigger0
'iLogicVb.RunRule("Gestandaardiseerde rol", "Rule0")
Dim BreakWithFactor As Double
Dim Bmaat=Parameter("Gestandaardiseerde rol.iam", "Bmaat")
Select Case Bmaat
Case <400
	ActiveSheet.View("Lengteaanzicht").ScaleString="1:2"
Case <1000
	ActiveSheet.View("Lengteaanzicht").ScaleString="1:5"
	BreakWithFactor=5
Case <1250
	ActiveSheet.View("Lengteaanzicht").ScaleString="1:7,5"
	BreakWithFactor=7.5
Case >1250
	ActiveSheet.View("Lengteaanzicht").ScaleString="1:10"
	BreakWithFactor=10

End Select

If "1:2" IsNot ActiveSheet.View("Lengteaanzicht").ScaleString Then
	DeleteBreaks
End If
End Sub

Sub DeleteBreaks
If (ActiveSheet.Name <> "Rol_compleet:1") Then Return
Dim viewL = ActiveSheet.View("Lengteaanzicht")
Dim view = viewL.View
If (view.BreakOperations.Count > 0) Then
  view.BreakOperations(1).Delete
End If

Dim xMid As Double = ActiveSheet.Sheet.Width / 2  'Helft van papierbreedte
Dim yMid As Double = ActiveSheet.Sheet.Height / 2  'Helft van papierhoogte
Dim modelDocName = IO.Path.GetFileName(viewL.ModelDocument.FullFileName)
Dim Bmaat As Double = Parameter("Gestandaardiseerde rol.iam", "Bmaat")
'If (Bmaat > 1000) Then Return
MessageBox.Show(Bmaat, "Bmaat=")
MessageBox.Show(Bmaat, "Bmaat=")
	
	Dim breakWidth As Double = (((Bmaat-300)/BreakWithFactor))	
	Dim startPt = ThisApplication.TransientGeometry.CreatePoint2d((xMid - (breakWidth*0.05)), yMid)
	Dim endPt = ThisApplication.TransientGeometry.CreatePoint2d((xMid + (breakWidth*0.05)), yMid)
MessageBox.Show(breakWidth, "Goed")
	
	'view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt)
	', BreakStyleEnum.kStructuralBreakStyle, 10, 0.3)
End Sub

 

Message 14 of 24
MjDeck
in reply to: adam.nagy

It looks like you fixed the compile error that you posted before. Here's an updated version that fixes a few other problems in the rule.

- BreakWithFactor is shared between the two Subs. It won't work if it's declared only in Main. The easiest way to do it is to declare it outside the Subs (at the VB Class level).  I moved Bmaat there as well.
- IsNot does not generally work for string comparison.  Use <> instead.

- Getting the midpoint of the sheet won't work unless the view is centered. It's better to use the view center. (I think we posted a simple example using the sheet center. We should have used the view center there as well.)

- The line to Add the break operation had an extra right parenthesis.


Mike Deck
Software Developer
Autodesk, Inc.

Message 15 of 24
HvHelden
in reply to: MjDeck

 

Hi Mike!

Thanks for sharing that knowledge! Smiley Happy

 

I didn't know that lines between 'subs' are also read by VB. I've copied your attachment to the iLogic rule, and it works fine! Thereafter, I was busy with figuring out how the value of breakWidth works; and the view is always between the drawing sheet.

Now, I would use not only an horizontal break on a view, but on vertical views too. (So that the length-shortening is in vertical direction). It gives me some bugs, while i changes the endPt and startPt by gives the yMid an (postive and negative, respectively) offset, and xMid where only xMid.

After that, i saw the breakstyleorientation is horizontal vs. vertical, and then it works fine!

Thank you all for helping!

 

HvHelden

 

Message 16 of 24

Andrew,

 

How were you able to insert multiple breaks? I've been trying to do the same but I get an error on the last line. Thanks!

 

If (ActiveSheet.Name <> "Sheet:1") Then Return
Dim viewL = ActiveSheet.View("A")
Dim view = viewL.View

For Each breakOp In view.BreakOperations
 breakOp.Delete
Next


Dim xMid As Double = ActiveSheet.Sheet.Width / 2
Dim modelDocName = IO.Path.GetFileName(viewL.ModelDocument.FullFileName)
Dim CP_THICKNESS As Double = Parameter(modelDocName, "CP_THICKNESS")
Dim HG_OAL As Double = Parameter(modelDocName, "HG_OAL")
Dim BORE As Double = Parameter(modelDocName, "BORE")
If (HG_OAL < 4) Then Return
x1= (((HG_OAL/2)-CP_THICKNESS)*2)
x2 = (BORE*.6)*2
Dim startPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid-x1, 0)
Dim endPt = ThisApplication.TransientGeometry.CreatePoint2d(xMid-X2, 0)
Dim startPt1 = ThisApplication.TransientGeometry.CreatePoint2d(xMid+X2, 0)
Dim endPt1 = ThisApplication.TransientGeometry.CreatePoint2d(xMid+X1, 0)

view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt, BreakStyleEnum.kStructuralBreakStyle)
view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt1, endPt1, BreakStyleEnum.kStructuralBreakStyle)

 

Message 17 of 24

Guys what you have done is very useful could somebody help me out, your solutions for me is like Chinese, I don't understand anything 🙂

 

Could you please send me a ilogic rule which I run for a single sheet and ask me the break gap size and set's it for all the breaks in all views in that sheet?

 

I tried selecting them all with a filter selection and then change but it only changes one of the selected randomly

 

Thanks!

Manuel Campos Costa
Message 18 of 24
MjDeck
in reply to: Manuelcamposcosta

@Manuelcamposcosta , here's a rule that might do what you want. It sets the gap. But maybe you also want to set the length of the break?


Mike Deck
Software Developer
Autodesk, Inc.

Message 19 of 24
MjDeck
in reply to: MjDeck

Here's the rule.


Mike Deck
Software Developer
Autodesk, Inc.

Message 20 of 24
Manuelcamposcosta
in reply to: MjDeck

I don't know what is called the length, is it the slider with Min. and Max.?

 

For me this is perfect it's exactly what I needed, I really appreciate your work, THANK YOU SO MUCH!!

 

I will try to understand what you did I'm starting now, my main difficulty is to understand were do you find all those name for the variables that control specific parts of inventor.

 

By the way is there any option to preview the part without break's? If I'm editing a drawing someone made I need to know if I'm not hiding details, but right know the only way I found was to delete all of them and then apply them as needed.

 

Edit: I found a way to toggle on and off trough display options of the view but I can't see where the breaks will be.

 

 

Manuel Campos Costa

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

Post to forums  

Autodesk Design & Make Report