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
Solved! Go to Solution.
Solved by Masibanda-CE. Go to Solution.
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:
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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.
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
Sebastian,
How are you testing that this script is working?
Cheers,
Gary
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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.
After adding the script...restart Advance Steel and then run the process
Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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.
Hmm the result is important, so you could work
Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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
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.
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
If this information was helpful, please use the Accept as Solution function, this make it easier for other users
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.