The function of checking the existence of the parent attribute

dynamic-component

#1

Hellow! Happy New Year!

I want to make a dynamic component with attributes that, if existing in the parent were used, otherwise it would be possible to specify manually.

Something like that:
=if(Exist(Parent!space),Parent!space,inputSpace)

How to implement?

attributExist.skp (22.9 KB)


#2

I don’t think you can. Referring to “parent!” will yield an error (visible only as red text in component attributes display), but there is no function to detect the error.

While I haven’t been able to imagine a use case, there may be one, so a “test” for the IF function like Excel’s “ISERR” would do the job, so you might put in a feature request.

But don’t hold your breath, Dynamic Components seem to be the lowest priority for SketchUp to improve.


#3

May be possible to apply something like that from Ruby, but how?


#4

Can’t help you there. My Ruby knowledge is virtually non-existent!


#5

I have not inspected the file, yet (mostly on a phone),
But what would be a usecase?
You can always implement an IF statement, which is,somehow, the most basic error handling:
IF(PARENT!attribute, PARENT!attribute, OtherValue)

Creation of new sttributes is not possible within the DC, so you must create a custom one.
The OtherValue being a customized attribute which the user can set in the option dialog


#6

Yes, but if the Parent!attribute does not exist, an error occurs that is not processed, the formula is highlighted in red.

And I just need to check the existence of the parent attribute …


#7

Ah! But what is the usecase?


#8

Meaning in nested components…
And if there is no such attribute in the parent, then you can simply change the characteristics of the component manually.

In general, parametric components and models.


#9

I tried this plugin:

if defined?($dc_observers)
  # Open SketchUp's Dynamic Component Functions (V1) class.
  # only if DC extension is active
 
class DCFunctionsV1

  protected
 
  # return 1 if exist and 0 if not
  # Usage: = framing_exist()
  def framing_exist(a_value)
if (defined?(a_value)).nil?
        return 1
else
	return 0
end#if

  end
  protected:framing_exist
 
 
end#class

end#if

error: unknown function


VARIABLE/FUNCTION - Use current valor?