cancel
Showing results for 
Search instead for 
Did you mean: 

existsObject question

Genius
Genius

I am trying to set up a class Method that does something if the predecessor's attribute = true. However, before I check that condition, I need to make sure that the predecessor actually has that attribute... if it doesn't exist, then it's an object from a different class and I don't care about it.

 

Is there a way to do this? I tried "existsObject," but it doest appear to be working. I'm assuming that it is just checking if the Object exists, no the Object's attribute.

 

code example:

if existsObject("?.pred(1).WorkStation")
     if ?.pred(1).WorkStation = false
          ?.pred(1).EntranceLocked := false
     end
end

 

Thanks in advance!

4 REPLIES

Re: existsObject question

Phenom
Phenom

if it is a user defined attribute, you can use attrNo, it returns a number greater than zero, if the attribute exists and zero, if the attribute doesn't exist or if this attribute is a build in attribute:

if ?.pred(1).getAttrNo("WorkStation") > 0
    if ?.pred(1).WorkStation = false
       ?.pred(1).EntranceLocked := false
    end
end

 

 or you check the name of the attribute

 

?.pred(1).isNameUnique("WorkStation") =false  --> attribute exists


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: existsObject question

Genius
Genius

Thank you Steffen.

 

I gave that a try and got an "Unknown identifier attrNo" error in the debugger. Any ideas?

Re: existsObject question

Phenom
Phenom
sorry,

should be getAttrNo

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: existsObject question

Genius
Genius

I was wondering why I counldn't find that method in the help ;-) 

 

Thanks Steffen! 

 

I tried both ways and they both worked. :-D