Surface Extension with loop

hugo_wy
Contributor
Contributor

Surface Extension with loop

hugo_wy
Contributor
Contributor

Hi.

I am trying to create multiple Surface Extensions using a Loop, after selecting multiple composite curves.

I am using Vbscript - HTM.

The code works fine if i only select one composite curve.

If i select more than one composite curve, it doesn´t work.

 

Here is the code:

 

<HTML>
<HEAD>
<script language="VBscript">
<!--

// Connect to PowerSHAPE
set PowerSHAPE = Window.external

// the routine called when the button is clicked..
Sub Apply_click()

//get the number of items in the current selection
num_items = PowerSHAPE.Evaluate( "SELECTION.NUMBER" )

IF (num_items = 0) then
MsgBox ("Nothing is selected")

Else

Dim i
i = 0

// loop through all the selection
For i = 0 to num_items - 1

// get the name
cName = PowerSHAPE.Evaluate("SELECTION.OBJECT[" & i & "].NAME")

PowerSHAPE.Exec("ADD COMPCURVE '" & cName & "'")
PowerSHAPE.Exec("CREATE SURFACE EXTENSION")
PowerSHAPE.Exec("ALONG SURFACE_INTERNALS")
PowerSHAPE.Exec("DISTANCE 4")
PowerSHAPE.Exec("APPLY")
PowerSHAPE.Exec("CANCEL")

Next

End If

End Sub

-->
</script>

</HEAD>
<BODY>
<H3>Extend surfaces</H3>
<FORM NAME=test>
<INPUT TYPE=button VALUE=" Apply " onClick=Apply_click() ><p>
</FORM>
</BODY>
</HTML>

 

 

0 Likes
Reply
Accepted solutions (1)
1,120 Views
7 Replies
Replies (7)

l.ponsaerts
Advocate
Advocate

Hi,

 

You have to unselect the composite curves first .

 

<script language="VBscript">

<!-- // Connect to PowerSHAPE

                set PowerSHAPE = Window.external

 

      // the routine called when the button is clicked..

                Sub Apply_click()

 

                                //get the number of items in the current selection

                                num_items = PowerSHAPE.Evaluate( "SELECTION.NUMBER" )

                                IF (num_items = 0) then

                                                MsgBox ("Nothing is selected")

                                Else

                                                Dim i

                                                i = 0

 

                                                // loop through all the selection

                                                For i = 0 to num_items - 1

                                                                // get the name

                                                                cName = PowerSHAPE.Evaluate("SELECTION.OBJECT[" & i & "].NAME")

                                                                Powershape.Exec("select clearlist")

                                                                PowerSHAPE.Exec("ADD COMPCURVE '" & cName & "'")

                                                                PowerSHAPE.Exec("CREATE SURFACE EXTENSION")

                                                                PowerSHAPE.Exec("ALONG SURFACE_INTERNALS")

                                                                PowerSHAPE.Exec("DISTANCE 4")

                                                                PowerSHAPE.Exec("APPLY")

                                                                PowerSHAPE.Exec("CANCEL")

                                                Next

                                End If

End Sub

--> </script>

</HEAD>

 

<BODY>

                <H3>Extend surfaces</H3>

                <FORM NAME=test>

                                <INPUT TYPE=button VALUE=" Apply " onClick=Apply_click() ><p>

                </FORM>

</BODY>

</HTML

0 Likes

hugo_wy
Contributor
Contributor

Thanks for respond quickly.

Still doesn´t work. 

See the attach video.

The code creates 2 surfaces with the same composite curve. 

I am working with Delcam PowerSHAPE 2015 (SP4 CR 15.1.46) 

 

Can you tell me how i can save my selection in a List or an Array?

0 Likes

l.ponsaerts
Advocate
Advocate

I apologize. My mistake, I didn't think. I was indeed thinking working on a list.

I don't have PS2015, we work with PS 2023.

Remove the select clearlist, it is useless.

To get a list of the names of the comp curves, try :


LIST compcurves = { }
LET i = 0
LET carry_on = ($i < $num_items)
WHILE $carry_on {
   LET comp_name = SELECTION.OBJECT[$i].name
   LIST_ADD $compcurves END $comp_name
   LET i = $i + 1
   LET carry_on = ($i < $num_items)
}

I didn't have the time to check it out, but hope it works.

0 Likes

hugo_wy
Contributor
Contributor

Hi.

I used your code and implemented in my MACRO.

The composite curves are in the LIST, but i am having trouble in accessing each item of the LIST.

The command "ADD COMPCURVE $compcurves($i_2)" isn´t working. I don´t know why. 

I tried many ways, without success, to PRINT the first item of the LIST:

print $compcurves (0)     

print $compcurves [0]

print $compcurves {0}

print $compcurves {[0]}

 

I convert the code to a MACRO:

 

LET num_items = SELECTION.NUMBER

IF ($num_items == 0) {
PRINT ERROR 'Nothing is selected'
RETURN
} Else {

//Cria uma LIST vazia e adiciona a seleção á lista
LIST compcurves = { }
LET i = 0
LET carry_on = ($i < $num_items)
WHILE $carry_on {
LET comp_name = SELECTION.OBJECT[$i].name
LIST_ADD $compcurves END $comp_name
LET i = $i + 1
LET carry_on = ($i < $num_items)
}

LET i_2 = 0
LET cond = ($i_2 < $num_items)

WHILE $cond {
select clearlist

ADD COMPCURVE $compcurves($i_2)
CREATE SURFACE EXTENSION
ALONG SURFACE_INTERNALS
DISTANCE 4
APPLY
CANCEL

LET i_2 = $i_2 + 1
LET cond = ($i_2 < $num_items)
}
}

0 Likes

l.ponsaerts
Advocate
Advocate
Accepted solution

There are some oddities in Powershape macro language ...

Hence, in automation projects I always try to use the API, instead of the raw macro commands.

First , one has to use [] instead of () when accessing the items in a list.

Second, when accessing a list, the list is 1 based instead of 0 based, so , the first item in the list has to be accessed as $compcurves[1] instead of $compcurves[0]

Third, and this is the strangest thing : although , in the macro , we use : STRING comp_name = SELECTION.OBJECT[$i].name , the variable $comp_name is not a string but an integer, as the name of the composite curve seems to be an integer. So, the command ADD COMPCURVE $compcurves[$i] generates an error.

A possible solution is to use a temporary string variable :

STRING temp = $compcurves[i]

ADD COMPCURVE $temp

That seems to work.

 

Here is the modified macro (tested on a surface in PM2023)

LET num_items = SELECTION.NUMBER
LIST compcurves = {}
STRING comp_name = ''
STRING temp = ''
IF ($num_items == 0) {
PRINT ERROR 'Nothing is selected'
RETURN
} Else {
//Cria uma LIST vazia e adiciona a seleção á lista
LET i = 0
LET carry_on = ($i < $num_items)
WHILE $carry_on {
$comp_name = SELECTION.OBJECT[$i].name
LIST_ADD $compcurves END $comp_name
LET i = $i + 1
LET carry_on = ($i < $num_items)
}
LET i_2 = 1
LET cond = ($i_2 <= $num_items)
WHILE $cond {
select clearlist
$temp = $compcurves[$i_2]
ADD COMPCURVE $temp
CREATE SURFACE EXTENSION
ALONG SURFACE_INTERNALS
DISTANCE 4
APPLY
CANCEL
LET i_2 = $i_2 + 1
LET cond = ($i_2 <= $num_items)
}
}
QUIT

 

l.ponsaerts
Advocate
Advocate

before and after ...

hugo_wy
Contributor
Contributor

Thanks.

 

It works perfectly.

 

With this new information about Lists i can do a lot of automation macros.

0 Likes