Workpoint - create with coords and name

Workpoint - create with coords and name

MarkyTomm
Enthusiast Enthusiast
648 Views
4 Replies
Message 1 of 5

Workpoint - create with coords and name

MarkyTomm
Enthusiast
Enthusiast

Hi All,

 

Just looking for a vba code snippet to create a workpoint within an already open part file.

 

The point will have x, y and z coords which i believe is this piece of code

 

Dim wp As WorkPoint

Set wp = oCompDef.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(xValue, yValue, zValue))

 

Can anyone help me with assigning a custom browser name to the point other than the default "Work Point1" please? 

 

Regards

Mark

Inventor pro 2020

0 Likes
649 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor

Hi, try the following code in VBA. It is to add the WorkPoint and rename it. 

 

Sub CreateWorkPoint()
    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    Dim oCD As PartComponentDefinition
    Set oCD = doc.ComponentDefinition
    Dim wp As WorkPoint
    Set wp = oCD.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(1, 2, 3))
    wp.Name = "My_WorkPoint"
End Sub

In ilogic rule 

    Dim doc As PartDocument
    doc = ThisApplication.ActiveDocument
    Dim oCD As PartComponentDefinition
    oCD = doc.ComponentDefinition
    Dim wp As WorkPoint
    wp = oCD.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(1, 2, 3))
    wp.Name = "My_WorkPoint"

I hope this helps with your work


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 5

MarkyTomm
Enthusiast
Enthusiast

Hi Sergio,

 

Thanks for your reply.

That is what i thought it should be and initially had it coded using the .name property but it throws a runtime error

"Method 'Name' of object 'Workpoint' failed"

 

I have found a workaround where by I rename all the points after they have all been created which for some reason works, but it is a bit of a hack as i would like to name them at point of creation

 

Any other thoughts?

 

Regards

Mark

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor
Hi, the code shared above is a basic code. If you want to add more than one point the rule will throw error because you cannot create another point with the same name of a previously created point.
Try the following code

 

Sub CreateWorkPoint()
    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    Dim oCD As PartComponentDefinition
    Set oCD = doc.ComponentDefinition
    
    Dim i As Integer
    i = 1
    
    Dim oWP As WorkPoint
    For Each oWP In oCD.WorkPoints
        If InStr(oWP.Name, "My_WorkPoint") <> 0 Then
        i = i + 1
        End If
    Next
    
    Set oWP = oCD.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(1, 2, 3))
    oWP.Name = "My_WorkPoint_" & i
    
End Sub

I hope this helps with your work


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 5

fullevent
Advisor
Advisor
 

Hello @Sergio.D.Suárez,

 

didn't try but should be

If InStr(oWP.Name, "My_WorkPoint_" & i ) <> 0 Then

right? 🤔

 

Greetings

 

 


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes