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

Script for filtering material

Masibanda-CE
Collaborator

Script for filtering material

Masibanda-CE
Collaborator
Collaborator

Does anyone know what needs to be searched/tested when writing a script to filter for a specific material?

Any other comments on my first script will also be appreciated.

Thanks

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function checkElement(Obj)

'Set value to false
CheckMaterial = False
'Get material

ObjMaterial = Obj.getMaterial              <------???????

'Check if material is what I want

If ObjMaterial = "What I want" Then

'If a match then set value to True

CheckMaterial = True

'if not a match

End If

End Function

 

0 Likes
Reply
Accepted solutions (1)
1,681 Views
25 Replies
Replies (25)

Tomislav.Golubovic
Advisor
Advisor

Why use a script when you can use the Search function and filter on the material you want?

0 Likes

Masibanda-CE
Collaborator
Collaborator
Drawing process. We need different presentations based on material.

Sebastian_Eiche
Mentor
Mentor

Yes I do it, your script have only one problem and should be corrected in:

ObjMaterial = Obj.Material

 

then it will work. I read, you want to part the detail drawing by sorting it for material:

  • be sure you create different processes for each material (a lot of work if you have a lot 😃
  • if you did this--> tip: you could assign the same prototype to the processes but create different naming for drawings, you could add this material name easily in the detailnaming
  • If you use the process step by step it will take time to run them, so therefore you could use the Drawing process suite, here you could add the processes and run them automatic.

I made there a few customizing with these scripts for different beam types + material +coating--> much work but the result are perfect named and sorted singlepart and mainpart drawing.


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator

Sebastian,

Thanks but that didn't work, or I didn't understand how to incorporate your comments.  Below is my latest attempt ... and failure:

'Returns true for UHMW_PE
Function MatchMaterial(Obj)
MatchMaterial = False
If Obj.IsKindOf(kPlateClass) = True Or Obj.IsKindOf(kBeamClass) =True Then
If Obj.IsKindOf(kBeamMaterial) = "UHMW_PE" Or Obj.IsKindOf(kPlateMaterial) = "UHMW_PE" Then
MatchMaterial = True
End If
End If
End Function

0 Likes

Sebastian_Eiche
Mentor
Mentor

Do you create such scripts in the past? It's much easier as you wrote. Your script clarify if it's a beam or plate, so why using an extra search for each material? Get the material, ask for beam or plate, set the token to true and that's it

 

'Returns true for UHMW_PE
Function MatchMaterial(Obj)
MatchMaterial = False
objmaterial=obj.material
If Obj.IsKindOf(kPlateClass) = True Or Obj.IsKindOf(kBeamClass) =True Then
objmaterial = "UHMW_PE" Then
MatchMaterial = True
End If
End If
End Function


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator

Sebastian,

This is my first attempt at writing a script. I was just trying everything and thought that I might have needed to filter for beams and plates first.

Now I'm getting this error:

Expected end of statement

Source Line: objmaterial = "UHMW_PE" Then

Line:5 Char:24

I saw that you had ONE If statement and TWO EndIf, so I tried this:


Function MatchMaterial(Obj)
MatchMaterial = False
objmaterial = obj.material
If objmaterial = "UHMW_PE" Then
MatchMaterial = True
End If
End Function

 

Still not working.

 

0 Likes

Sebastian_Eiche
Mentor
Mentor

The code which is definitely working on my side is:

Function MatchMaterial(Obj)
MatchMaterial= False
If Obj.IsKindOf(kBeamClass) or Obj.IsKindOf(kPlateClass) Then
mat=obj.Material
If mat="UHMW_PE" then
MatchMaterial= true
End If
End If
End Function

 

But if you use processes and add this script normally, it's not necessary to ask for beam or plate, because the process itself will use the objecttype in the modelobject field. If you use the different detailstyle for beams and plates, it will not be necessary, this part is only needed if you use one detail style for all objects.


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator

Sebastian,

How are you testing that this script is working?

Cheers,

Gary

0 Likes

Sebastian_Eiche
Mentor
Mentor

I test it with a model of mine. I replace the material with one I use: 'S235' and then I set some object material with this material. After doing the process I could see which objects are detailed and which not.


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator

I must be doing something wrong then because it doesn't work for me. When running a drawing process and using the model object filter with this script it just skips right over that entry in the style map.

0 Likes

Sebastian_Eiche
Mentor
Mentor

After adding the script...restart Advance Steel and then run the process


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator
Accepted solution

This is the code that worked ... provided by Yuri Kim:

 

Function checkElement(Obj)
    MatchMaterial = False
    mat = obj.Material 
    If mat = "[Material name]" then 
        MatchMaterial = true
    End If
    checkElement = MatchMaterial
End Function

Sebastian_Eiche
Mentor
Mentor

This is the same code, but without checking if it's a beam or plate, so by using this, all objects will be used...


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

Masibanda-CE
Collaborator
Collaborator

Sebastian, I don't understand why, but the use of "checkElement" as the function name and setting it to equal the value of the MatchMaterial made the difference on my end.

0 Likes

Sebastian_Eiche
Mentor
Mentor

Hmm the result is important, so you could work


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

ChristianBlei
Advisor
Advisor

Hi Gary,

 

if you like to dive deeper into scripting in AS:

Mihai Dobrecsu from the AS devolpment team gave a lecture at AU some years ago.

Extending-Detailing-Capabilities-Scripting.

 

Because if was curious, I made some tests. The name of the function has to be checkElement, if you vary the function name the script fails. Upper case or lower case does not matter.

What you can do to test your scripts is to use messageboxes.

As an example:

 

Function CheckElement(Obj)
CheckElement= False
MsgBox "Hello"

End Function

 

When you have changed the script, you have to save all the changes. You do not need to restart AS, but you have to update the used database before you run the process. (Home/Settings/ Update Defaults)

 

best regards,

Christian

 

 

 

 

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw

Masibanda-CE
Collaborator
Collaborator

Thanks Christian, I wish it was easier to find those resources! Even the Autodesk personnel that were corresponding with me about this didn't know that "checkElement" MUST be the name of the function. It took half a dozen emails to get to the solution.

0 Likes

Sebastian_Eiche
Mentor
Mentor

Maybe this was the issue, I only change the script text itself...was not known to me too


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

0 Likes

juanraXSVE3
Participant
Participant

Hi.

I try to use this script to make a filter by material to make a drawing proces. 

In this case, i want to draw only a Aluminum beams (in spanish "Aluminio")

But, when i use this script, Advance said "impossible create a draw"

 

What's wrong?

 

Function checkElement(Obj)
MatchMaterial = False
mat = obj.Material
If mat = "Aluminio" then
MatchMaterial = true
End If
checkElement = MatchMaterial
End Function

0 Likes