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
MyResult
The result I want.
Solved! Go to Solution.
Solved by ilker_akay. Go to Solution.
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?
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.
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.
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.
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.
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
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.
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.
Let me work on this and I will get back to uou. I'm running into the same thing.
i am messing with the camera and trying to get it to work consistanly then after that i will be complete
I HAVE figured out the camera and settings, let me package it up and see if this is what you'd like
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.
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.
1 - Result
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.
I think it will be better understood this way😔
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.
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".
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.