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: 

Creating a drawing view Two named faces with ilogic

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
ilker_akay
602 Views, 20 Replies

Creating a drawing view Two named faces with ilogic

Hello, we have many parts during the design phase and it takes a lot of time to prepare technical drawings. To speed up the process, I discovered ilogic and API in Inventor. There are many sample codes on the forum, I understand the logic a little. What I want to do now is;
1- I can do this with the code I shared as an example. There is a scale problem, I could not figure out the reason.
2. The starting plane or axis of each part may be different. To overcome this, I made 2 definitions in the piece. "Front face" and "Top face". I want to show the piece accordingly in the view. How can I do this with ilogic or c# api?

 

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

Dim templatePathAndName As String = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Metric\Ansi (mm).idw"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templatePathAndName, True)

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oX As Double = 0
Dim oY As Double = 0
				
Dim oSheet As Sheet = oDDoc.ActiveSheet
oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize
Dim oView As DrawingView = oSheet.DrawingViews.AddBaseView(oPDoc, oTG.CreatePoint2d(oX, oY), 1/1 , ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle,)
Dim oView2 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView, oTG.CreatePoint2d(50, 0), DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
Dim oView3 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView, oTG.CreatePoint2d(0, -50), DrawingViewStyleEnum.kFromBaseDrawingViewStyle)

Dim owBw As Double
Dim owBh As Double
Dim scale1 As Double
Dim scale2 As Double
Dim scale As Double

Dim space As Double = 3  '30mm

owBw = space + oView.Width + space + oView2.Width + space
owBh = space + oView.Height + space + oView3.Height + space

scale1 = oSheet.Width  / owBw
scale2 = oSheet.Height / owBh

scale = 1/ Round( 1/Min(scale1, scale2), 0, MidpointRounding.ToPositiveInfinity)

oView.Scale =  scale
space = (space * scale)*10
oView.Position = oTG.CreatePoint2d(space + (oView.Width / 2), oSheet.Height + (-space - (oView.Height / 2)))
oView2.Position = oTG.CreatePoint2d(oView.Position.X + (space + (oView2.Width / 2)), oView.Position.Y)
oView3.Position = oTG.CreatePoint2d(oView.Position.X, oView.Position.Y - (space + (oView3.Height / 2)))

 

Named Enities

ilker_akay_0-1721016116728.png

MyResult

ilker_akay_1-1721016241866.png

 

The result I want.

ilker_akay_2-1721016306093.png

 

 

 

20 REPLIES 20
Message 2 of 21
AndrewHumiston
in reply to: ilker_akay

would you mind attaching the drawing document and model document? that would help me work out the scale issue. i have a series of code that will auto scale based on the space. i can adapt that part of yours to fit.

 

is that what you are trying to do?

Message 3 of 21
ilker_akay
in reply to: AndrewHumiston

i added sample part1.ipt and video.ilogic code is in the model and uses the standard template for idw file.
I think I solved the scaling problem. I confused oview.width and oview.height.
My main problem is that part drawings do not start from a standard plane. (YZ, XZ, ZY can be one of the planes). When this is the case, it becomes impossible to create a standard main view. The solution is to assign names to the faces in the model. As you can see in the example, I am assigning names to two surfaces. I want to create the main view based on "My Front Face" and "Top Face" and these faces. "My Front Face" will always be the front face in the main view, "Top Face" will always be facing up in the main view. In short, I want to create the main view in the technical drawing according to these faces. I hope I could explain.

Message 4 of 21
AndrewHumiston
in reply to: ilker_akay

naming the geometry can be a cumbersome activity. i have adapted the practice of using the xy plane always as my 'ground' plane, i know that can be tough when there are multiple people involved in modeling. i would recommend coming up with a standard of how parts need to be drawn and barring that i would add a rule to easily name the faces by clicking on them, to ensure the name is correct and is always the same, as that can be an issue if something is spelled incorrectly or in the wrong format.

 

let me see what i can come up with. 

Message 5 of 21
ilker_akay
in reply to: AndrewHumiston

It's teamwork and everyone designs as they see fit. It is difficult to impose a certain standard. Surfaces can be named or selected by clicking. The important thing is to be able to create the main view according to the selected surfaces, independent of the planes. Thus, a standard rule is created. Since the same rule will be applied to each part, all technical drawings from the assembly file will be prepared as desired to be displayed at once with a single click. Since this is not the rule I want, parts drawn in different planes create different appearances. This causes the bends to be left behind in some parts.
I think the rule I want is not something difficult or impossible. I can only do simple things in the ilogic section. Especially the camera and rotation matrices and vectors seem very complicated to me, I don't understand.

Message 6 of 21
AndrewHumiston
in reply to: ilker_akay

Here is what i've come up with so far. its a quick rule you can run in a part file to quickly name the face as "My Front Face"

 

the next step will be adding the code to orient the views as you want them.

 

 

Message 7 of 21
ilker_akay
in reply to: ilker_akay

I found an example similar to what I want here 

I can partially adapt it. I added the first piece I made and was able to partially customize.

but I haven't achieved the exact result I want yet.
now how can i rotate the face i named with "TopFace" up

 

Message 8 of 21
AndrewHumiston
in reply to: ilker_akay

What I'm running up against it that the code, needs to find a design view representation. i am currently piecing something together for you in your part files to name the entity and setup a design view and orient it correctly. then when you add the view to the drawing it will be with that specific view name to enable you to be consistant each time.

Message 9 of 21
ilker_akay
in reply to: AndrewHumiston

In the example I found, it does this by defining one face and two axes. If it is possible to do this with two face assignments, this will be a more practical way. It can reflect any face I specify into the design view as the front face. What I can't figure out right now is how to rotate the face I assigned as "top face" so that it is up. In its current final form, it is looking down. Camera, vectors and matrices are a very complex subject for me. I can't make any headway from now on. I'm stuck at this point.

Message 10 of 21
AndrewHumiston
in reply to: ilker_akay

Let me work on this and I will get back to uou. I'm running into the same thing.

Message 11 of 21
ilker_akay
in reply to: AndrewHumiston

Have you made any progress?

Message 12 of 21
AndrewHumiston
in reply to: ilker_akay

i am messing with the camera and trying to get it to work consistanly then after that i will be complete

 

Message 13 of 21
AndrewHumiston
in reply to: ilker_akay

I HAVE figured out the camera and settings, let me package it up and see if this is what you'd like

 

Message 14 of 21
ilker_akay
in reply to: AndrewHumiston

I'm looking forward to sharing it with you. I wonder how it is?

Message 15 of 21
AndrewHumiston
in reply to: ilker_akay

Here is the code i came up with.

 

there are a few things you will need to do:

Line 1, you may comment this line out if you want to not have a dialog box, this allows the user to set what ever name they'd like.

 

Line 2, un-comment this line if you'd like a static name that can be changed by altering the string "My Front Face"

 

Line 90,  need to insert the name of your template. i have it pulling the directory from your project file, so change "TestTemplate.idw" to the name you would use "Your Template Name.idw" make sure you have the file type.

 

this rule will be run from a part file. you will run the rule, it will ask you which face to select as your front face. click the face and it will create a view representation and a named entity. you need the viewrep to create the idw as you wanted with a specific face in the orientation. i have added the code to create the drawing and 3 base views.

 

if you want to change the spacing of the views:

Line 94 for the base location of the first view.

Line 95 alter the +50 to change how far to the right the projected view is

Line 96 alter the -50 for the distance 'down' your view is located.

 

i hope this answers your request. please like if you agree and accept the solution so others can find a topic like this easier.

 

once you give me the thumbs up i will annotate and get the code ready for a final version.

 

 

Message 16 of 21
ilker_akay
in reply to: AndrewHumiston

Thank you for your help and efforts.
I did not see the same change as a result.
First, you can look at the "MyFrontFace" face. In both codes.
I think the second face I identified was confused by the name similarity to "TopFace".
Let's call this "MyTopFace". The second face I assign is normally the bottom of the piece.
And he is still looking down according to the view in the drawing.
I couldn't see any facial action on the second one.

Let me explain it this way with pictures.

1).The first face assigned("MyFrontFace") or selected will be the front face in the drawing. No problem so far. A drawing appears based on the selected face.

 

ilker_akay_3-1721410056584.png

 

1 - Result

ilker_akay_1-1721409466857.png

 

2).  2. The selected or assigned("MyTopFace") needs to rotate up, 180 degrees according to its appearance in the drawing. and this is the result I want to achieve.

 

ilker_akay_4-1721410164620.png

 

I think it will be better understood this way😔

Message 17 of 21
AndrewHumiston
in reply to: ilker_akay

hello,

 

hey no worries! i think this is what you are asking for. i take it that you are using 1st angle projection?

 

here is the code, i hope this is what you are looking for.

Message 18 of 21
ilker_akay
in reply to: AndrewHumiston

The purpose of the 1st face I assign("MyFrontFace") is to always turn that face into the front face in the drawing view.
The purpose of the 2nd face I assigned ("MyTopFace") is to use the assigned face so that it is always on the top side like in the picture.
I can't rotate it up because I don't know how to find the direction of "MyTopFace".

Message 19 of 21
AndrewHumiston
in reply to: ilker_akay

Let me work more on this Monday I can figure this out 

Message 20 of 21
ilker_akay
in reply to: AndrewHumiston

Finally I somehow succeeded.

I'm adding the code and ipt file here. Maybe it could be useful to someone.

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

Dim templatePathAndName As String = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Metric\Ansi (mm).idw"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templatePathAndName, True)

Dim oNamedEntities As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim oFace1 As Face = oNamedEntities.FindEntity("MyFrontFace")
Dim oFace2 As Face = oNamedEntities.FindEntity("MyTopFace")

If oFace1 Is Nothing Then
	MessageBox.Show("MyFrontFace not found!", "Error!")
	Return
End If

If oFace2 Is Nothing Then
	MessageBox.Show("MyTopFace not found!", "Error!")
	Return
End If

Dim oPlane1 As Plane = oFace1.Geometry
Dim oPlane2 As Plane = oFace2.Geometry

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oX As Double = 0
Dim oY As Double = 0
				
Dim oSheet As Sheet = oDDoc.ActiveSheet
oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize

Dim oView As DrawingView = oSheet.DrawingViews.AddBaseView(oPDoc, oTG.CreatePoint2d(oX, oY), 1 / 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, )

Dim oCam As Camera = oView.Camera
Dim oPoint As Point
oPoint = oCam.Target.Copy
oPoint.TranslateBy(oPlane1.Normal.AsVector())
oCam.Eye = oPoint
oCam.UpVector = oPlane2.Normal.Copy
oCam.ApplyWithoutTransition

Dim oView2 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView, oTG.CreatePoint2d(10, 0), DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
Dim oView3 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView, oTG.CreatePoint2d(0, -10), DrawingViewStyleEnum.kFromBaseDrawingViewStyle)

Dim owBw As Double
Dim owBh As Double
Dim scale1 As Double
Dim scale2 As Double
Dim scale As Double

Dim space As Double = 3  '30mm

owBw = space + oView.Width + space + oView2.Width + space
owBh = space + oView.Height + space + oView3.Height + space

scale1 = oSheet.Width  / owBw
scale2 = oSheet.Height / owBh

scale = Min(scale1, scale2)
oView.Scale =  scale
space = (space * scale)

oView.Position = oTG.CreatePoint2d(space + (oView.Width / 2), oSheet.Height + (-space - (oView.Height / 2)))
oView2.Position = oTG.CreatePoint2d(oView.Center.X + (oView.Width / 2) + space + (oView2.Width / 2), oView.Position.Y)
oView3.Position = oTG.CreatePoint2d(oView.Position.X, oView.Position.Y - (oView.Height / 2) - space - (oView3.Height / 2))

 

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report