How do I add a workpoint at an xyz coordinate

How do I add a workpoint at an xyz coordinate

JBEDsol
Collaborator Collaborator
1,146 Views
9 Replies
Message 1 of 10

How do I add a workpoint at an xyz coordinate

JBEDsol
Collaborator
Collaborator
 Public Sub AddWorkPlanebyOriginOffset(strWPName As String, strOffsetPln As String, dblDist As Double)

        Dim pntOffset As WorkPoint

        If appApp.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
            Dim ptdocCurrent As Inventor.PartDocument
            ptdocCurrent = appApp.ActiveDocument

            Dim ptcdCurrent As PartComponentDefinition
            ptcdCurrent = ptdocCurrent.ComponentDefinition

            If strOffsetPln = "XY Plane" Then
                pntOffset = ptcdCurrent.WorkPoints
            ElseIf strOffsetPln = "YZ Plane" Then

            Else

            End If


            ptcdCurrent.WorkPlanes.AddByPlaneAndOffset(ptcdCurrent.WorkPlanes("XY Plane"),)

        Else
            Dim assydocCurrent As Inventor.AssemblyDocument
            assydocCurrent = appApp.ActiveDocument

            Dim assycdCurrent As AssemblyComponentDefinition
            assycdCurrent = assydocCurrent.ComponentDefinition


        End If

        Dim wpPlane As Inventor.WorkPlane
        wpPlane = cdCurrent.

    End Sub

 

This is where I'm at with trying to make a routine to add a workplane offset by some user parameters.  When I look at the workplane it needs an object so I set about creating a point at and xyz location.  I can't seem to get it to work, can't figure out how to add via xyz. 

0 Likes
Accepted solutions (1)
1,147 Views
9 Replies
Replies (9)
Message 2 of 10

Michael.Navara
Advisor
Advisor
Accepted solution

I don't uderstand your code and what are you try to do. But This code creates workpoint at specified coordinates

 

Dim x = 1
Dim y = 2
Dim z = 3

Dim activePart As PartDocument = ThisDoc.Document

Dim oPoint As Point = ThisApplication.TransientGeometry.CreatePoint(x, y, z)
Dim oworkPoint As WorkPoint = activePart.ComponentDefinition.WorkPoints.AddFixed(oPoint)

 

and this code creates work plane offseted from YZ work plane

Dim oWorkPlanes As WorkPlanes = ThisDoc.Document.ComponentDefinition.WorkPlanes
Dim oPlane = oWorkPlanes(1) 'YZ WorkPlane
Dim oOffset = 1 ' 1 cm
oWorkPlanes.AddByPlaneAndOffset(oPlane, oOffset)
Message 3 of 10

JBEDsol
Collaborator
Collaborator

That is much easier, thank you.

0 Likes
Message 4 of 10

chris
Advisor
Advisor

@Michael.Navara concerning your above code, is there a way for the grounded work point to update if the rule is ran again where the X.Y,Z numbers are changed? Currently it just creates another work point, but can it be created so that it just updates the original work point created, and can the rule contain a line of code to allow the work point to be named within the code.

 

I ask because I have to create a few dozen work points, but I also need them to be able to update and change values

0 Likes
Message 5 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @chris ,

Here is a quick example of redefining an existing workpoint location.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim x = 1
Dim y = 2
Dim z = 3
Dim activePart As PartDocument = ThisDoc.Document
Dim oworkPoint As WorkPoint = Nothing
Dim wpName = "Best WorkPoint Ever"

Try
	oworkPoint = activePart.ComponentDefinition.WorkPoints.Item(wpName)		
	z = InputBox("Enter Z", "iLogic", oworkPoint.Point.Z)
Catch
	oworkPoint = Nothing	
End Try

Dim oPoint As Point = ThisApplication.TransientGeometry.CreatePoint(x, y, z)

If 	oworkPoint Is Nothing Then 
	oworkPoint = activePart.ComponentDefinition.WorkPoints.AddFixed(oPoint)
	oworkPoint.Name = wpName
End If

oworkPoint.SetFixed(oPoint)

EESignature

0 Likes
Message 6 of 10

chris
Advisor
Advisor

@Curtis_Waguespack When I set up and run your rule, it has a dialog box asking for an "Enter Z", what is that for? 

If I edit the iLogi rule and manually change the X,y,z, numbers, why is it asking for "Enter Z"?

0 Likes
Message 7 of 10

chris
Advisor
Advisor

@Curtis_Waguespack Nevermind, I figured it out

 

0 Likes
Message 8 of 10

chris
Advisor
Advisor

@Curtis_Waguespack the only problem I have run into is that when I try and type in something like this;

-(67*12)+6.375    for   67'-6-3/8"

for the dialog box for X,Y, or Z it gives me this error.

 

chris_0-1712252588934.png

 

0 Likes
Message 9 of 10

chris
Advisor
Advisor

@Curtis_Waguespack  it would be nice if Inventor would just allow XYZ in parameters for the location of a work point. I like how simple your above code is, but those numbers are not stored anywhere, nor can the user see what the numbers are in a list, not to mention it doesn't like equations for inputs.

 

0 Likes
Message 10 of 10

_dscholtes_
Advocate
Advocate

@chris wrote:

it would be nice if Inventor would just allow XYZ in parameters for the location of a work point.


You could add a function to your code that evaluates your equations and uses the end results as input for creating workpoints to create this behaviour. The  'Units of Measure' object is quite powerfull in evaluating expressions and converting units.

 


@chris wrote:

...but those numbers are not stored anywhere...


You can retrieve those numbers from the workpoint itself:

 

oWorkPoint.Point.X, oWorkPoint.Point.Y and oWorkPoint.Point.Z

 

 

 

0 Likes