Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Problem creating transient geometry in part

Cadkunde.nl
Collaborator

Problem creating transient geometry in part

Cadkunde.nl
Collaborator
Collaborator

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

 

Cadkundenl_0-1710864210398.png

 

Any help/example is greatly appreciated

 

0 Likes
Reply
Accepted solutions (2)
418 Views
8 Replies
Replies (8)

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

Cadkunde.nl
Collaborator
Collaborator

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 :slightly_smiling_face:

 

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.

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

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

EESignature

(Not an Autodesk Employee)

JelteDeJong
Mentor
Mentor
Accepted solution

This example creates a (very thin) box and aligns it with an edge that you selected. 

JelteDeJong_0-1710974578921.png

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.

EESignature


Blog: hjalte.nl - github.com

Cadkunde.nl
Collaborator
Collaborator

Thanks for all the help, I will delve into this.

0 Likes

Cadkunde.nl
Collaborator
Collaborator

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.

0 Likes

Cadkunde.nl
Collaborator
Collaborator

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

0 Likes

Cadkunde.nl
Collaborator
Collaborator

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

0 Likes