- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Forum,
I have a hard time getting the following.
I have a script that automates creating plates with flanges
Problem: Some flanges that are angled +- 10 degrees from the orientation of the XY Plane (Ground plane)
Need to get the angle of the ground plane. For visual aestetics, but also dirt and such.
So before the flange is created, I want to make a "plane". So I can measure the angle from this plane to the ground plane. and adjust my angle before the flange is created.
The plane should be from the front face of the plate, angled from the top edge, then angled (90 deg for example)
But I have a hard time with transient geometry / transientBRepp / Client Graphics
I think i need to create this using transientgeometry.createplane
For debugging i want this visual with client graphics
Any help/example is greatly appreciated
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Cadkunde.nl. Are you attempting to provide a 'preview' of a feature before you create it? Either way, creating a simple transient Plane object will not work for that purpose, because it has no size or outline. Something else that you could likely get to look right might be a WorkPlane, because you can control its size with two Point objects. But if using it for preview purposes, you would wither need to turn its visibility off, or delete it once you were done with it. There are several 'Add' type methods for creating a WorkPlane, starting from the WorkPlanes object (Document.ComponentDefinition.WorkPlanes).
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried the workplane rotate around edge.
I think it was workplanes.addbylineplaneandangle
But the workplane creation keeps giving me an error when using input edge and face rather than axis and workplane.
Tried transient geometry plane but i mess up with the inputs as well, keeps crashing.
Ideal would be if i could get a temporary face with maybe brep somehow.
Because I have a good code to get the real angle between 2 faces (not shortest angle between 2 infinite workplanes)
Im kinda frustrated on the failed attempts ![]()
The goal is to have a plane to measure with groundplane XY. And adjust the angle of the flange i want create next. Ideally visible for debugging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I might not be much help with the more complex TransientBRep & ClientGraphics type stuff. I have only dabbled with the TransientBRep new body creation stuff (one API Sample here, includes both) a couple times for body copy type functionality. And only barely dabbled with ClientGraphics stuff on a few brief occasions for very basic things like showing a point or text. I just have not had the need to dig deeper into them at this point.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This example creates a (very thin) box and aligns it with an edge that you selected.
Public Sub Main()
Dim oTg = ThisApplication.TransientGeometry
Dim edge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select an edge.")
Dim line As LineSegment = edge.Geometry
Dim startPoint = line.StartPoint
Dim translationVector = oTg.CreateVector(startPoint.X, startPoint.Y, startPoint.Z)
Dim vector1 = oTg.CreateVector(0, 0, 1)
Dim vector2 = line.Direction.AsVector()
Dim matrix As Matrix = oTg.CreateMatrix()
matrix.SetToRotateTo(vector1, vector2)
matrix.SetTranslation(translationVector)
Dim partDoc As PartDocument = ThisDoc.Document
Dim transBRep As TransientBRep = ThisApplication.TransientBRep
Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry
Dim boxMinPoint As Point = transGeom.CreatePoint(0, 0, 0)
Dim boxMaxPoint As Point = transGeom.CreatePoint(10, 0.15, 50)
Dim box As Box = transGeom.CreateBox()
box.Extend(boxMinPoint)
box.Extend(boxMaxPoint)
Dim minBoxSurface As SurfaceBody = ThisApplication.TransientBRep.CreateSolidBlock(box)
Dim cGraphics As ClientGraphics = CreateBox(partDoc, minBoxSurface, matrix)
MsgBox("CHeck the preview")
cGraphics.Delete()
End Sub
Private Function CreateBox(partDoc As Document, surface As Object, matrix As Matrix) As ClientGraphics
Dim cGraphics As ClientGraphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Add("OrientedRangeBox")
Dim surfacesNode As GraphicsNode = cGraphics.AddNode(1)
surfacesNode.Transformation = matrix
Dim surfGraphics As SurfaceGraphics = surfacesNode.AddSurfaceGraphics(surface)
Dim targetAppearance As Asset
Try
targetAppearance = partDoc.Assets.Item("Clear - Blue")
Catch
Dim sourceAppearance As Asset = ThisApplication.AssetLibraries.Item("314DE259-5443-4621-BFBD-1730C6CC9AE9").AppearanceAssets.Item("InvGen-001-1-2") ' "Clear - Blue"
targetAppearance = sourceAppearance.CopyTo(partDoc)
End Try
surfacesNode.Appearance = targetAppearance
ThisApplication.ActiveView.Update()
Return cGraphics
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In my case I need Brep instead of client graphics. (for measuring, then deleting)
Also need to look better at vectors and matrix.
I worked with all kinds of things in the API, but this area gives me headaches, and avoided it a little until now.
Time to fully understand these components. I got good examples in both your replies to start thanks to you guys.
I think I'll manage from here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
With the examples I built the following:
I'm able to make a solid feature that I can angle much like a flange, and be able to measure.
Public Sub Main() Dim partDoc As PartDocument = ThisDoc.Document Dim oCompDef As PartComponentDefinition = partDoc.ComponentDefinition Dim transBRep As TransientBRep = ThisApplication.TransientBRep Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry Dim edge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select an edge.") Dim egdeLength As Double = ThisApplication.MeasureTools.GetMinimumDistance(edge.StartVertex, edge.StopVertex) Dim line As LineSegment = edge.Geometry Dim startPoint = line.StartPoint Dim translationVector = transGeom.CreateVector(startPoint.X, startPoint.Y, startPoint.Z) Dim vector1 = transGeom.CreateVector(0, 0, 1) Dim vector2 = line.Direction.AsVector() Dim matrix As Matrix = transGeom.CreateMatrix() matrix.SetToRotateTo(vector1, vector2) matrix.SetTranslation(translationVector) Dim boxMinPoint As Point = transGeom.CreatePoint(0, 0, 0) Dim boxMaxPoint As Point = transGeom.CreatePoint(0.3, -10, egdeLength) Dim box As Box = transGeom.CreateBox() box.Extend(boxMinPoint) box.Extend(boxMaxPoint) Dim oBody As SurfaceBody = transBRep.CreateSolidBlock(box) transBRep.Transform(oBody, matrix) matrix.SetToRotation(90*PI/180, vector2, line.StartPoint) transBRep.Transform(oBody, matrix) partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(True) Dim oBaseFeature As NonParametricBaseFeature = oCompDef.Features.NonParametricBaseFeatures.Add(oBody) partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(False) End Sub
This is kinda what I wanted, but not sure if it is what I need.
Just need a 'face' in the position of the flange, before a flange is created, to measure it with workplane XY
I can measure the difference in angle in the direction of the flange.
If inventor measures an angle in the width direction of the flange, I can ignore it
If the angle of the flange is in +30deg/-30deg range of workplane XY, I should align the flange to be created with the workplane XY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Figured out that oBody.face(4) is what I need to measure angle
I dont need to create the feature at all (except maybe for debugging)
So this is perfect. Thanks all