Jump to content

[SOLVED] surface Attached Parts


Recommended Posts

Question, how can I find surface attached parts?

I know how to find it to stack attached parts


foreach (AttachNode subAttach_node in attach_node.attachedPart.attachNodes.Where(n => n.attachedPart != null))
{
List<MyModule> myModules = subAttachPart.FindModulesImplementing<MyModule>();
}

part has a poperty called srfAttachNode, but how can I use this?

Can anyone help me?

Edited by FreeThinker
Link to comment
Share on other sites

That foreach loop is not going to yield anything. Youre finding all the modules in a given part only and not storing them anywhere.

What you're looking for is Part.attachMode. But it depends what you want. If you want all the surface attached parts including the parent part, something like this:

public List<MyModule> GetModules()
{
List<Part> srfParts = new List<Part>(this.part.children.Where(c => c.attachMode == AttachModes.SRF_ATTACH)); //Adds the surface attached children parts
if (this.part.attachMode == AttachModes.SRF_ATTACH) { srfParts.Add(this.part.parent); } //Adds the parent part if this part is surface attached
if (srfParts.Count <= 0) { return new List<MyModule>(); } //No need to loop if there's no elements
List<MyModule> modules = new List<MyModule>();
foreach(Part part in srfParts)
{
modules.AddRange(part.FindModulesImplementing<MyModule>()); //Adds each part's modules
}
return modules;
}

If you don't want to include the parent part, you would do something like this:

public List<MyModule> GetModules()
{
return new List<MyModule>(this.part.children.Where(c => c.attachMode == AttachModes.SRF_ATTACH) //Finds the surface attached parts
.SelectMany(p => p.FindModulesImplementing<MyModule>())); //Returns the modules
}

Link to comment
Share on other sites

If you don't want to include the parent part, you would do something like this:

public List<MyModule> GetModules()
{
return new List<MyModule>(this.part.children.Where(c => c.attachMode == AttachModes.SRF_ATTACH) //Finds the surface attached parts
.SelectMany(p => p.FindModulesImplementing<MyModule>())); //Returns the modules
}

Excelent. This looks what I need.

Edited by FreeThinker
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...