Advance Steel Forum
Welcome to Autodesk’s Advance Steel Forums. Share your knowledge, ask questions, and explore popular Advance Steel topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script for filtering material

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
Masibanda-CE
1515 Views, 25 Replies

Script for filtering material

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

 

25 REPLIES 25
Message 2 of 26

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

Message 3 of 26

Drawing process. We need different presentations based on material.
Message 4 of 26

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

Message 5 of 26

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

Message 6 of 26

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

Message 7 of 26

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.

 

Message 8 of 26

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

Message 9 of 26

Sebastian,

How are you testing that this script is working?

Cheers,

Gary

Message 10 of 26

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

Message 11 of 26

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.

Message 12 of 26

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

Message 13 of 26
Masibanda-CE
in reply to: Masibanda-CE

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

Message 14 of 26

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

Message 15 of 26

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.

Message 16 of 26

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

Message 17 of 26

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
Message 18 of 26

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.

Message 19 of 26

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

Message 20 of 26
juanraXSVE3
in reply to: Masibanda-CE

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report