SketchUp组件放置的观察者

您好 我正在制作一个小插件来增加我的工作流程。 我创建了一个导入组件的订单。 放置后,我想更新其属性ra_poste和ra_fourniseur的两个下拉列表? 组件在放置后仍处于选中状态。 我想我可以使用该选择来触发其元属性选项的更新。 只有将组件放置在模型上的时间脚本才能展开,并且选择尚未填充 我认为有必要用观察者监视放置是否正确为了达到以下效果, 查看文档和示例,我不知道如何使用它,以及要测试什么反馈才能继续脚本, 请帮助我了解观察者是如何工作的。 晚安, 这里是ruby api sketchup文档的摘录是我的代码 #Commande N°20 IMPORTER COMPOSANT MAIN OEUVREdef = = model.get_attribute(\"AttributRapport\", \"fournisseurs\",\"\") {|a|a+ = $dc_observers.get_latest_class dcs.redraw_with_undo(entity)end#fin de composant_main_oeuvre_cmd 查看此回复以及其他主题的链接… 重新创建移动工具-#8由DanRathbun 2创建 place_component()是一种奇怪的方法。 它创建一个撤消操作,因此您无法在另一个撤消操作中对其进行调用。 它也是异步的。这意味着Ruby代码不会停止并等待组件实例放入模型中。 因此希望阅读这些旧主题可以帮助您了解编码方法。 请学习使用右上角的放大镜菜单搜索类别。 您不会使用onPlaceComponent观察者回调。相反,您知道定义是什么,所以您将使用DefinitionObserver#onComponentInstanceAdded回调。 作为一个示例,您创建了一个小的混合观察者: class PlaceInstanceSpydef == 21013 # ComponentTool# User has begun the component placement.# Status bar text says \"Place component.\"elsif tool_id == 21048 # MoveTool# User has clicked and placed the instance.# Stop watching the tools collection:tools.remove_observer(self)# User is left with MoveTool active and new instance selected.elsif tool_id == 21022 # SelectionTool# User has cancelled the placement via ESC key.# Stop watching the definition:@definition.remove_observer(self)# Stop watching the tools collection:tools.remove_observer(self)endendend 稍后在代码中放置组件时使用它: # Attach Observer to cdef definition, (self is parent module):cdef.add_observer(PlaceInstanceSpy.new(cdef, self))# Start the placement:model.place_component(cdef) 谢谢Dan 开始时,我有点难以理解 但是下面是代码的工作原理,随着被调用组件的插入,属性post和supplier的下拉列表都得到了很好的更新! 在模型的attributereport字典中,我将position和supplier的不同值存储在各自的属性中。不同的值存储在以\"|\"作为分隔符的字符串中。真管用!但这是监管吗? 再次感谢 对于剩下的部分,我将直接打开一个新的帖子。 这里是代码 class PlaceInstanceSpy def = = = $dc_observers.get_latest_classdcs.redraw_with_undo(instance)# Remove this observer instance. No longer needed.definition.remove_observer(self) end def onActiveToolChanged(tools, tool_name, tool_id)if tool_id == 21013 # ComponentTool# User has begun the component placement.# Status bar text says \"Place component.\"elsif tool_id == 21048 # MoveTool# User has clicked and placed the instance# Stop watching the tools collection:tools.remove_observer(self)# User is left with MoveTool active and new instance selected.elsif tool_id == 21022 # SelectionTool# User has cancelled the placement via ESC key.# Stop watching the definition:@definition.remove_observer(self)# Stop watching the tools collection:tools.remove_observer(self)end endend#Commande N°20 IMPORTER COMPOSANT MAIN OEUVREdef> simjoubert: but here is the code which works, with the insertion of the called components, the drop-down lists of the attribute post and supplier are well updated! I meant for you to put that code in a method out in the parent module. (This is what the @parent引用被传递给了观察者,…因此它可以用来调用这个外部方法。)辛茹伯特: 在模型的AttributeReport字典中,我存储了位置和供应商的不同值在各自的属性中。不同的值存储在以\"|\"作为分隔符的字符串中。真管用!但这是监管吗? 使用管道符号(\"|\")是可以的。 APIUI::inputbox方法也使用它来接受下拉选择列表的选择。 很容易将值数组连接到管道分隔字符串> 或哈希> 按照定义键/值对的顺序返回values数组。 If(对于示例)您希望按排序键的顺序返回值,然后… h.sort.to_h.values.join(\"|\")> Hello Dan the \"composant_main_oeuvre_cmd\" command creates an observer \"onComponentInstanceAdded\" which calls a method \"ajoutAttributsComposantImporter(definition, instance)\" in return to create the attributes for the placed component If I take out the definition of the attributes in an methode outside the \"PlaceInstanceSpy\" class Sketchup returns the error \"Error: # \" I can\"t find the correct syntax here is the code of the class # component placement event.class PlaceInstanceSpy def == 21013 # ComponentTool# User has begun the component placement.# Status bar text says \"Place component.\"elsif tool_id == 21048 # MoveTool# User has clicked and placed the instance# Stop watching the tools collection:tools.remove_observer(self)# User is left with MoveTool active and new instance selected.elsif tool_id == 21022 # SelectionTool# User has cancelled the placement via ESC key.# Stop watching the definition:@definition.remove_observer(self)# Stop watching the tools collection:tools.remove_observer(self)end endend #Fin Class PlaceInstanceSpy 这里是名为 def ajoutAttributsComposantImporter(definition, instance)# by calling a method in the = = aname[0]definition.set_attribute DCDICT,\"ra_article\",snamedefinition.set_attribute DCDICT,\"_ra_article_access\",\"TEXTBOX\"definition.set_attribute DCDICT,\"_ra_article_formlabel\",\"Article\"definition.set_attribute DCDICT,\"_ra_article_formulaunits\",\"STRING\"definition.set_attribute DCDICT,\"_ra_article_label\",\"ra_article\"definition.set_attribute DCDICT,\"_ra_article_options\",\"&\"definition.set_attribute DCDICT,\"_ra_article_units\", \"STRING\"#Creer un attribut COMMENTAIREdefinition.set_attribute DCDICT,\"ra_commentaire\",\"\"definition.set_attribute DCDICT,\"_ra_commentaire_access\",\"TEXTBOX\"definition.set_attribute DCDICT,\"_ra_commentaire_formlabel\",\"Commentaire\"definition.set_attribute DCDICT,\"_ra_commentaire_formulaunits\",\"STRING\"definition.set_attribute DCDICT,\"_ra_commentaire_label\",\"ra_commentaire\"definition.set_attribute DCDICT,\"_ra_commentaire_options\",\"&\"definition.set_attribute DCDICT,\"_ra_commentaire_units\", \"STRING\"#Creer un attribut POSTEdefinition.set_attribute DCDICT,\"ra_poste\", \"\"definition.set_attribute DCDICT,\"_ra_poste_access\",\"LIST\"definition.set_attribute DCDICT,\"_ra_poste_formlabel\",\"Poste\"definition.set_attribute DCDICT,\"_ra_poste_formulaunits\",\"STRING\"definition.set_attribute DCDICT,\"_ra_poste_label\",\"ra_poste\"definition.set_attribute DCDICT,\"_ra_poste_units\", \"STRING\"#Mise à jour liste = = definition.get_attribute(\"SU_DefinitionSet\", \"Price\", 0)definition.set_attribute DCDICT,\"ra_prix_unitaire\",spricedefinition.set_attribute DCDICT,\"_ra_prix_unitaire_access\",\"TEXTBOX\"definition.set_attribute DCDICT,\"_ra_prix_unitaire_formlabel\",\"Prix unitaire\"definition.set_attribute DCDICT,\"_ra_prix_unitaire_formulaunits\",\"FLOAT\"definition.set_attribute DCDICT,\"_ra_prix_unitaire_label\",\"ra_prix_unitaire\"definition.set_attribute DCDICT,\"_ra_prix_unitaire_options\",\"&\"definition.set_attribute DCDICT,\"_ra_prix_unitaire_units\", \"EUROS\"#Creer un attribut QTT saisie manuellementdefinition.set_attribute DCDICT,\"ra_qtt\",\"1\"definition.set_attribute DCDICT,\"_ra_qtt_access\",\"TEXTBOX\"definition.set_attribute DCDICT,\"_ra_qtt_formlabel\",\"QTT\"definition.set_attribute DCDICT,\"_ra_qtt_formulaunits\",\"FLOAT\"definition.set_attribute DCDICT,\"_ra_qtt_label\",\"ra_qtt\"definition.set_attribute DCDICT,\"_ra_qtt_options\",\"&\"definition.set_attribute DCDICT,\"_ra_qtt_units\", \"FLOAT\"#Creer un attribut Unite liste#valeur par défaut selon le nom de la définition du composantcase snamewhen = DCDICT,\"_ra_unite_options\",\"&Unité=u&Forfait=ft&Heure=h&Mètres=m&Surface=m²&Volume%20m3=m³&Volume%20Litres= = $dc_observers.get_latest_classdcs.redraw_with_undo(instance)# On creer un calque> and finally the code of the initial command to place the component #Commande N°20 IMPORTER COMPOSANT MAIN OEUVREdef> simjoubert: If I take out the definition of the attributes in an methode outside the \"PlaceInstanceSpy\" class Sketchup returns the error \"Error: # \" This means that you are defining methods at the top level ObjectSpace的方法的代码,它是类Object. 意味着您的方法将成为全局方法,并被其他所有代码对象继承。 您的所有代码必须位于唯一的顶级命名空间模块中。 那么您的每个扩展都必须位于命名空间模块的子模块中。 如果您将extend self放在扩展子模块的顶部,它的方法可以无条件地相互调用。 你好,丹 我花了很长时间才找到! 我在你的帖子中找到了一个空白的模板,你可以很好地编写插件,我意识到我已经声明了名称空间和模块,但只在插件的声明文件和加载程序中声明了,而不是在主程序中声明了。 从观察器调用命令可以工作 多亏了你

SketchUp在扩展仓库中更改扩展的价格不再是即时的…为什么?

我想把这个假期所有的分机都降价,但由于新分机仓库的变动,我不能降价。以前更改插件的成本非常容易,现在需要永远的时间。可以像以前那样更改吗?谢谢!现在是否需要您创建一个新草稿并再次进行审阅?办公室已在假期关闭,因此我们目前正在积压处理审阅队列。它应该很快就会恢复正常。我们正在计划清理编辑/提交过程,以便再次只有一个新的RBZ需要一个新的草稿和审阅。tt琰su:现在是否需要您创建一个新草稿并再次审阅?是的...

日期:2021-06-26 02:00:03 浏览:565

SketchUp访问组的实体以应用/更改材质

您好,据我所知,可以在组中添加实体。是否有任何方法可以访问组的特定面(例如:大小为1米、1米、1米的立方体,由6个面组成)并在每个面上应用不同的材料。谢谢这是完全可能的,尽管你需要使用的技巧取决于你对你想要的脸的了解程度油漆。一些示例:- 如果您自己创建了面,您可以立即应用材质>- 如果您知道感兴趣的面已经在组中,您可以检索它们>然后需要决定数组中的哪个面将接收哪个面材料。那个可以通过测试每个面的正常。注意grep将在组中找到所有的面孔,如果有其他人在场的话,这些面孔可能会包含比你想处理的更多的面孔我也是。...

日期:2021-06-26 05:00:05 浏览:702

SketchUp保持数值而不考虑单位

我已经开始开发一个插件,我希望输入框中的值以当前单位输入。当前如果我指定>如果模型是mm,它就可以工作,但是如果是英寸就不行。如果我只是有了相同的>如果模型是英寸而不是毫米就可以工作。有没有某种自动转换,我可以把@radius的值建立为当前的工作单位?Class:Length 1Class:Numeric 1我很欣赏文档的链接,但我已经了解了这一点,仍然不知道如何转换为当前单位。确保将默认的inputbox维度值设置为Sketchup长度。然后它将自动转换并保存为长度值(以英寸为单位)并以模型单位显示,自动...

日期:2021-06-26 06:00:03 浏览:967

SketchUp复制组/组件时出现持续的ID错误

rigin(在片段中设置)。对于你的mod,明显的旋转中心是短线的末端(右侧):这不是我的目标。这实际上使用了Sasquatch:此外,用户可以通过文本指定副本的数量(使用\"s\")供参考,所有本机工具都使用\"s\"表示边的数量,使用\"x\"表示副本的数量。明白了,按照建议从\"s\"更改为\"x\"。与此同时,我弄明白了为什么我的\"卷积\"代码产生了正确的转换,而你的代码却没有…在你的代码中,你添加每个新实例,同时对其执行转换,这只会导致相对于预选组的局部轴的转换,而是关于模型空间(或worlds...

日期:2021-06-26 07:00:04 浏览:727

SketchUpC点/引导点的样式是否可行?

我正在测试用点云做房子模型。导入点(dxf),SketchUp将其转换为许多cpoint。使用这些进行捕捉的建模很好。我的问题是:是否可以\"样式化\"cpoints?比如尺寸、颜色等?更多的视觉控制可能会更好。另外,API中是否有其他实体可以将这些CPoint转换为更小/更精细/更可定制的CPoint?通常,他们应该在渲染选项散列(样式)中采用指导色的颜色,如果\"按标记颜色\"处于禁用状态。如果\"按标记颜色\"处于启用状态,则他们将使用层/标记颜色显示。实验表明,指定材质不会使他们按材质显示。(即,指...

日期:2021-06-26 07:00:04 浏览:628

SketchUp如何获取html值

从HTML对话框获取值时出现问题。This is callback function at sketchup.add_action_callback(\"receiveValue\") { |not_used, id, val|receive_value(id,val)}def receive_value(id,>I try to get input value like this, but I can\"t get>I can\"t get dlgValues, so I checked the size...

日期:2021-06-26 12:00:03 浏览:797

SketchUp如何判断V-Ray渲染是否已完成

你好!我正在使用V-Ray自动渲染,但遇到了一个问题,即无法知道渲染何时完成。目前我渲染场景,然后等待20秒,更改模型的材质,然后再次渲染,但如果渲染在5秒内完成,这是一个非常无效的系统。到目前为止,我已经完成了尝试了live_scene.renderer?布尔值和几个VRay::Renderer::IDLE_变量,但没有成功。问题是,在从扩展渲染循环时,布尔值不会更改,因此代码总是超时,即使渲染更快完成。下面是一些示例+=1if i>20puts\"超时渲染\"BreakEndModel.commi...

日期:2021-06-26 14:00:01 浏览:1141

SketchUp rubyapi:将工具栏停靠到其他工具栏

我已经创建了自己的工具栏,但是我不知道如何将它自动停靠到行上,所有其他工具栏都已经位于行上(在下拉菜单下)。有什么提示吗?DanRathbun在post#2中解决的用户必须进行对接。您所能做的就是调用#restore。用户必须进行对接。你所能做的就是打电话给#restore4...

日期:2021-06-26 15:00:04 浏览:799

SketchUp从多个曲面创建多个组

大家晚上好,我有一张约2000个小表面的图纸,我想分组制作,然后推拉。创建曲面后,如果图形是新的,下面的脚本工作得非常好。当我只选择第二个或第三个曲面时,它仍然运行得很快,但是当我选择了一个并且在脚本中有一个以前创建的组时,它只以一半甚至更少的速度运行,脚本变成\"没有响应\",但最终在后台运行一段时间后它就完成了。即使我重新启动sketchup甚至pc并重新运行脚本,它仍然很慢。当我分解所有组并进行另一个选择时,脚本又变快了。如果我做错了什么,也许有人能告诉我。我的笔记本电脑有16 GB内存,图形卡是,并...

日期:2021-06-26 20:00:05 浏览:620

SketchUp有没有办法加快添加面和边的速度?

我正在创建一个进口商。我用实体添加面以及实体添加边导入一个模型,但是要花很多时间。54234个面需要11秒来添加面85417个边需要9秒来添加边这是一个简单的模型。对于复杂模型,创建面和边的时间太长,无法接受。我怎样才能加快速度?谢谢。您是否创建了撤消操作并在操作过程中关闭了UI?- Sketchup::Model#start_operation- Sketchup::Model#commit_operation您是否考虑过创建虚拟多边形网格…- Geom::PolygonMesh4class…然后在操作中...

日期:2021-06-27 00:00:03 浏览:836