TopSolid V6 - PushElementOnStack

All topics about specific development with COM interface, LIP language, API in VB, ...

Moderators: remi77, Daniel, jacs

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Sat Feb 08, 2020 10:57 pm

Hello everyone, I'm looking to "click" (select) the element "@ 2352" which corresponds to a view of a drawn document (.dft).

For example, here is my code:

Code: Select all

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        TopApp = New TopSolid.Application
        TopDoc = TopApp.CurrentDocument
        TopElt = TopDoc.Elements.Item("@2352")

        With TopApp

            .PushElementOnStack(TopElt)
            .ExecuteMacroKeepStack("C:\Missler\V619\d\l\analyse")

        End With

End Sub
The purpose of this is to execute the "analysis" function of TopSolid, and rather than manually clicking on the view ("@ 2352") I would like to do it automatically. I tried to use the "PushElementOnStack" function without success. Anyone have any idea?

Thank you..

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Fri Feb 21, 2020 6:39 pm

Good morning all,

To summarize and relaunch my subject, I would have to modify the .lip file of the analyze function by integrating the element "@ 2352" and therefore withdraw its functioning since the function requires an element to analyze.

Cordially

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Mon Mar 02, 2020 3:49 pm

You have to define the correct fileformat

Code: Select all

Dim TopDoc As TopSolid.DocumentDesign ‘For Draft-File reduced functions
Dim TopDoc3D As TopSolid.Document ‘For Top-File and Draft-File many cool functions
You have to search the right way

Code: Select all

Dim TopApp as TopSolid.Application
Dim TopDoc3D As TopSolid.Document ‘For Top-File
Dim TopElt as TopSolid.Element 'Element like @2352

TopApp = New TopSolid.Application
TopDoc3D = TopApp.CurrentDocument

try
	TopElt = TopDoc.Elements.Item("@2352") ‘!!! Not the correct way !!!
Catch ex As Exception
End Try

TopElt = dim TopDoc3D.SearchElementByName("$SET") 'maingroup of Top-File
For Each TopElt2 as TopSolid.Element in TopElt '$SET = Maingroup
	if TopElt2.identifier="2352" then
	 	'Your Code what to do with TopElt2 
	 	'ExecuteMacroKeepStack
	end if
Next

'Faster if you directly know the element identifier
TopElt = dim TopDoc3D.SearchElementByName("@2352") 'your element directly
'How to push information to a Macro

Code: Select all

With TopApp
	.PushElementOnStack(TopElt )
	.ExecuteMacroKeepStack("C:\Missler\V619\d\l\your_own_analyse")
End With
Now we have to check the "analyse.lip"
There is a sub function "$TOPHOME/d/l/getinfo"
inside this file "getinfo.lip" this line are the solution

Code: Select all

LABEL	label
LABEL	plab
INT	pid
INT	n
INT	mass

label? plab? pid? mass? DWgetinfo n!
n? 0 > If
	n?
	UWinfo
Then
We have to read from right to left:
label? plab? pid? mass? DWgetinfo n!
  • n! = a integer will be set (! = set variable)
  • DWgetinfo = the right command
  • mass? = Question Physical informations YES/NO as integer 1/0 will be get (? = get variable)
  • pid? = a integer will be get (? = get variable)
  • plab? = (maybe the selected element as) a label will be get (? = get variable)
  • label? = (maybe the selected element as) a label will be get (? = get variable)
  • n? 0 > If = If n is > 0 then...
  • n?
    UWinfo

    = get the [n] Info
to identify the different integer Variables, we have to feedline each (? = get variable)

Code: Select all

label? plab? pid? mass? DWgetinfo n!
FeedLine n? PrintI  
FeedLine pid? PrintI
FeedLine mass? PrintI
plab? PrintI FeedLine
label? PrintI FeedLine
In my test case
n = 20 (set by command DWgetinfo )
pid = 5 (??? don't know, but it stand for pick id ???)
mass = 0 (no physical information, the question/answer from original command analyse.lip)
plab = same as label (just set here your element)
label = same as plab (just set here again your element)

easy going, we got it. :D

Code: Select all

LABEL	label
LABEL	plab
INT	pid
INT	n
INT	mass

label!
label? plab! 

label? plab? 5 0 DWgetinfo n!
n? 0 > If
	n? UWinfo
Then
Last edited by Holzknoten on Wed Mar 04, 2020 5:00 pm, edited 1 time in total.
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Mon Mar 02, 2020 9:14 pm

Good evening to you,

I tried the code but without success,
I stopped at vb code, I did not look at your .lip file (I would take the time later) because if I block before, I suppose that it does not serve to go further ^^

I struggled to explain my concern, and therefore my need:

I'm looking to save a plan, which is generated from a .top in the same place as this.
To save the plan, I need the path to the .top, to recover it I use the "edit model" function which corresponds to the "edmodel.lob" file.
By launching this function, I get the save path which I then use to save my plan.

To explain, I put a video below and my entire code.

https://youtu.be/hs2p-CRN96Y

The code :

Code: Select all

Public Class Form1

    Dim TopApp As TopSolid.Application
    Dim TopDoc As TopSolid.Document
    Dim TopElt As TopSolid.Element
    Dim Folder As String
    Dim Trouver As String
    Dim Cherche As String
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        TopApp = New TopSolid.Application
        TopDoc = TopApp.CurrentDocument

        With TopApp

            .ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")

        End With

        Folder = TopApp.CurrentDocument.Path

        TopDoc.Visible = True

        If System.IO.Directory.Exists(Folder & "\PLAN") = False Then

        End If

        System.IO.Directory.CreateDirectory(Folder & "\PLAN")

        Cherche = Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft"

        If My.Computer.FileSystem.FileExists(Cherche) Then

            If MsgBox("Il existe déjà un plan avec la même désignation et la même référence, voulez-vous vraiment l'écraser ?", vbYesNo + vbCritical, "Attention !") = vbNo Then
                Me.Close()
            Else
                TopDoc.SaveAs(Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft")
            End If
        Else
            TopDoc.SaveAs(Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft")
        End If

        Me.Close()

    End Sub

End Class
When you have seen everything, I just have to tell you that finally I try to avoid point "5)", no more no less! I hope I have been more specific, thank you for the time.

To return to the .lip, I thought that modifying the file "analyse.lip" (it would be the same principle for "edmodel.lip") and that by directly indicating the element "@ 2352" rather than asking a question it would automate the function (and therefore I avoid point "5)". In the end it's just that I can't do EVERYTHING via the API. But maybe my logic is bad and we can avoid going through .lip!

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Tue Mar 03, 2020 5:32 pm

Point 5) What is the job at Point 5?

EXE File launching is discripted inside this forum. viewtopic.php?f=5&t=784&p=2706&hilit=EXE#p2706
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Tue Mar 03, 2020 5:53 pm

In the video, we see that when I launch the application (the code in VB.NET), we launch the "edmodel.lip" function.

This function requires "the part to be edited" (in the video I zoom in on it, with yellow fluorescent, look at 0:40 to 1:05).
I click on the "@ 2352" item, and it's "clicking" that I'm trying to avoid.
Since in the end, we always click on the element "@ 2352", this element corresponds to a view.

Each time I launch my program, I have to click on this item, and I would like to avoid it (since I know it in advance).

________________________________________________________________________________________________________

EDIT :
Holzknoten wrote:
Mon Mar 02, 2020 3:49 pm
You have to define the correct fileformat

Code: Select all

Dim TopDoc As TopSolid.DocumentDesign ‘For Draft-File
Dim TopDoc3D As TopSolid.Document ‘For Top-File
-------------------------------------------------------------------------------

I do this :

Code: Select all

Dim TopApp As TopSolid.Application
Dim TopDoc As TopSolid.Document
Dim TopElt As TopSolid.Element
-------------------------------------------------------------------------------
Holzknoten wrote:
Mon Mar 02, 2020 3:49 pm
'How to push information to a Macro

Code: Select all

With TopApp
	.PushElementOnStack(TopElt )
	.ExecuteMacroKeepStack("C:\Missler\V619\d\l\your_own_analyse")
End With
-------------------------------------------------------------------------------

So i do :

Code: Select all

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

TopApp = New TopSolid.Application
TopDoc = TopApp.CurrentDocument
TopElt = TopDoc.SearchElementByName("@2352")

With TopApp

.PushElementOnStack(TopElt)
.ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")

End With

End Sub
-------------------------------------------------------------------------------

But it's didn't work, i think my element is not a element ? :roll:

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Wed Mar 04, 2020 6:44 am

Function "PushElementOnStack" working correct.

OK back to the startpoint.
In your code you have try to set the variable TopElt. But TopElt keeps empty because your Element was not found.
You have to understand that inside a DRAFT file there are elements other as in TOP file.

My Example @112 inside TOP file
Top-File.png
@112 inside DRAFT file
Image

IN DRAFT we are talking about a sub element of other elements (Views -> View -> Reference -> Elements -> Element @112)
We have to check the names of each Element in the draft

Code: Select all

TopApp = New TopSolid.Application
Dim TopDoc3D As TopSolid.Document ‘My mistake: its possible for DRAFT and for TOP
TopDoc3D = TopApp.CurrentDocument
Dim myelements As String
For Each TopElt In TopDoc3D.Elements
	myelements = myelements & Chr(13) & TopElt.Name
Next
MsgBox(myelements)
Result of messagebox
Name of elments.png

Code: Select all

TopElt = TopDoc3D .Elements.Item("$SET_ENTITIES_VIEWS")
'OR
TopElt = TopDoc3D.SearchElementByName("$SET_ENTITIES_VIEWS")
Dim TopElt2 as TopSolid.Element
myelements = ""
For Each TopElt2 In TopElt.Elements
	myelements = myelements & Chr(13) & TopElt2.NameOrIdentifier
Next
MsgBox(myelements)
Result of messagebox
Image
So we got the element position.
Image

That is what i know. We have to get inside sub groups to get the real element.
So my last "For Each" could do this.

Code: Select all

For Each TopElt2 In TopElt.Elements
	if TopElt2.identifier = "@43" then
		exit for
	end if
Next
With TopApp
	.PushElementOnStack(TopElt2)
	'We have to check what kind of lob you need? Analyse? And then we have to modify it like in my email to you.
	.ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")
End With
'We have to check what kind of lob you need? Analyse?
Then use the modified version of my Post: #p5776 (scroll to bottom of post)

VB TIPP:
You have to debug your VB program.
Use "PAUSE" (red dot on left in the image below) to pause your program and use "mouse over" to analyze the current setting of variables like the TopElt2 before you "PushElementOnStack".
Image
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Wed Mar 04, 2020 6:04 pm

Holzknoten wrote:
Wed Mar 04, 2020 6:44 am
So we got the element position.
Holzknoten wrote:
Wed Mar 04, 2020 6:44 am
That is what i know. We have to get inside sub groups to get the real element.
I didn't have this notion at all, it is now understandable!
Thank you ;)
Holzknoten wrote:
Wed Mar 04, 2020 6:44 am
VB TIPP:
You have to debug your VB program.
Use "PAUSE" (red dot on left in the image below) to pause your program and use "mouse over" to analyze the current setting of variables like the TopElt2 before you "PushElementOnStack".
Image
Thanks for its also! Very useful .. I know the principle but no idea how to use it! It's great !!
Holzknoten wrote:
Wed Mar 04, 2020 6:44 am
'We have to check what kind of lob you need? Analyse? And then we have to modify it like in my email to you.
It is the "edmodel" file that interests me (and not the analysis, it is an error on my part)

I look at your previous messages as indicated, I see if it is adaptable. Thank you

____________________________________________________________________________________________________________________________

EDIT :

I had to modify the following line by removing the "@"

Code: Select all

        For Each TopElt2 In TopElt.Elements
            If TopElt2.Identifier = "@43" Then
                Exit For
            End If
        Next
and adapting it to my case (@2352)

Code: Select all

        For Each TopElt2 In TopElt.Elements
            If TopElt2.Identifier = "2352" Then
                Exit For
            End If
        Next

Then I don't really have an error, but no value is assigned to "TopElt2"

Code: Select all

        With TopApp
            [b].PushElementOnStack(TopElt2)[/b]
            'We have to check what kind of lob you need? Analyse? And then we have to modify it like in my email to you.
            .ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")
        End With
I modified the .lip but unable to compile it. I replaced the "label" and the "plab" in a raw way by "2352".

Code: Select all

LABEL	2352
LABEL	2352
INT	pid
INT	n
INT	mass

label!
label? plab! 

label? plab? 5 0 DWgetinfo n!
n? 0 > If
	n? UWinfo
Then
But I think it is no longer suitable since it is rather "edmodel" that counts now

Starting from your logic, I opened the "edmodel.lip"
I tried to modify different "label" but without success !! Sorry I do not manage too much in the field ..

I know I am doing the wrong thing because it is impossible to compile. With the default file it compiles well.

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Thu Mar 05, 2020 5:34 pm

you missunderstood how to use pushtoStack

Wrong lip:

Code: Select all

LABEL	2352
LABEL	2352
Right lip:

Code: Select all

LABEL	labone
LABEL	labtwo
labone! (get element from stack from VB)
Inside VB: Yes you are right if we use Identifier in VB we have to use Identifier without "@" ...

Code: Select all

If TopElt2.Identifier = "2352" Then
Right VB: if you have set TopElt2 with one element

Code: Select all

With TopApp
            .PushElementOnStack(TopElt2)
            .ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")
End With
Inside VB: Complete working code for allready open DRAFT file.

Code: Select all

Dim TopApp As TopSolid.Application
Dim TopDoc3D As TopSolid.Document ‘My mistake: its possible for DRAFT and for TOP
Dim TopElt , TopElt2 as TopSolid.Element

TopApp = New TopSolid.Application
TopDoc3D = TopApp.CurrentDocument
TopElt = TopDoc3D.SearchElementByName("$SET_ENTITIES_VIEWS") 'only in a DRAFT file

For Each TopElt2 In TopElt.Elements
    If TopElt2.Identifier = "2352" Then
        With TopApp
              .PushElementOnStack(TopElt2)
              msgbox(TopElt2.nameoridentifier)
              .ExecuteMacroKeepStack("C:\Missler\V619\d\frame\view\l\edmodel.lob")
        End With
    End If
Next
Debugging is the biggest need to get code working.
Please give me your complete VB Code and i can debug it.
Last edited by Holzknoten on Fri Mar 06, 2020 5:36 am, edited 1 time in total.
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Thu Mar 05, 2020 5:46 pm

Hi,

My entire code :

Code: Select all

Public Class Form1

    Dim TopApp As TopSolid.Application
    Dim TopDoc As TopSolid.Document
    Dim TopElt As TopSolid.Element
    Dim TopElt2 As TopSolid.Element
    Dim Folder As String
    Dim Trouver As String
    Dim Cherche As String
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        TopApp = New TopSolid.Application
        TopDoc = TopApp.CurrentDocument
        TopElt = TopDoc.SearchElementByName("$SET_ENTITIES_VIEWS")

        For Each TopElt2 In TopElt.Elements

            If TopElt2.Identifier = "2352" Then

                With TopApp

                    .PushElementOnStack(TopElt2)
                    MsgBox(TopElt2.NameOrIdentifier)
                    .ExecuteMacro("C:\Missler\V619\d\frame\view\l\edmodel.lob")

                End With

            End If

        Next

        Folder = TopApp.CurrentDocument.Path

        TopDoc.Visible = True

        If System.IO.Directory.Exists(Folder & "\PLAN") = False Then

        End If

        System.IO.Directory.CreateDirectory(Folder & "\PLAN")

        Cherche = Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft"

        If My.Computer.FileSystem.FileExists(Cherche) Then

            If MsgBox("Il existe déjà un plan avec la même désignation et la même référence, voulez-vous vraiment l'écraser ?", vbYesNo + vbCritical, "Attention !") = vbNo Then
                Me.Close()
            Else
                TopDoc.SaveAs(Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft")
            End If
        Else
            TopDoc.SaveAs(Folder & "\PLAN\" & TopDoc.Reference & "-" & TopDoc.Designation & ".dft")
        End If

        Me.Close()

    End Sub

End Class

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Mon Mar 09, 2020 3:54 pm

what return the MsgBox?

Code: Select all

MsgBox(TopElt2.NameOrIdentifier)
only the msgbox return correct identifier we can modify the lip/lob file
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Mon Mar 09, 2020 5:53 pm

My result :

Image

He find the good "@"

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Tue Mar 10, 2020 6:01 am

perfect. now we are shure, we Push the Element "2352" On Stack.
Your main question was "How to pushElementOnStack".

For Example:
We Push the Element "25" as first on Stack.
And we Push the Element "2352" as second on Stack.

Now there are two Elements inside the "Stack". Stack is like a small cache.

Inside a lip-file we "pull and remove" each item in backwards order from the Stack seperatly.

Code: Select all

(Comments are bracketed and lip will do nothing with this text)
(This file is working only if we have allready PushElementOnStack in VB or VBA)
LABEL labone (define a empty variable for one Element = LABEL)
LABEL labone (define a empty variable for one Element = LABEL)
labone! (pull and remove last pushed item "2352" from Stack ans save inside variable)
labtwo! (pull and remove last pushed item "25" from Stack ans save inside variable)
The "!" pull and remove last pushed item from Stack.

Your need to check again the Lip file "C:\Missler\V619\d\l\analyse.lip"
Inside this file you need this sub function only.

Code: Select all

$TOPHOME/d/l/getinfo
= "C:\Missler\V619\/d/l/getinfo"
This file i modified by myself, allready. See my last post #pr5776
Just compile this lip file to a new lop file with "TopLip".

Code: Select all

LABEL	label
LABEL	plab
INT	pid
INT	n
INT	mass

label!
label? plab! 

label? plab? 5 0 DWgetinfo n!
n? 0 > If
	n? UWinfo
Then
by Holzknoten

Fred_44780
Private
Private
Posts: 9
Joined: Sat Mar 16, 2019 1:19 pm
TopSolid Module: TopSolid'SheetMetal
TopSolid Version: 6.19

Re: TopSolid V6 - PushElementOnStack

Unread post by Fred_44780 » Tue Mar 10, 2020 5:55 pm

Hi,

It's perfect everything works !!

Thank you for the time you have given me .. And especially for the explanations that allow me to understand how it works. There are few resources and few users, it's great to have taken the time to help me.

Thank you..

Holzknoten
Master Corporal
Master Corporal
Posts: 43
Joined: Fri Apr 29, 2011 7:16 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.17
Location: Hannover
Contact:

Re: TopSolid V6 - PushElementOnStack

Unread post by Holzknoten » Wed Mar 11, 2020 5:19 am

D@vid wrote:
> Hi!
>
> When the topic is solved or when you get an proper answer, I strongly
> recommand to use the topic icon feature!
> You just edit the first post of the discussion and select Topic icon.
>
> Thanks!

Please change the icon for your first pos of this Topic.
by Holzknoten

Post Reply