In drupal 7 how to add a link to a node which creates another node related to the previous being visible only if a user has not yet done so? I have a node #1 of content type A. If the user equals a certain role AND has not yet done the following, show a link within node#1 saying "create node of type B".

If the user clicks this link, he may create a new node of type B. Then, when looking at node#1 again, the link disappears (or changes), since the user has already created another node from within node#1.

If you would delete that last created node and visit node#1 again, you would again have the possibility to create a node of type B which would automatically be related to the respective node, in this case node#1.

How can you do that?
I can see couple of ways to do it.

1) add the module http://drupal.org/project/node_limit

2) Create a menu with node/add/contentA 

3) add this block to the node of the type content A

4) to do the third step you would need to add alias to the content A nodes by following method

Setup a URL alias pattern for content A
Click on Configuration in the admin menu, and look for "URL Aliases". 
One of the tabs is called "Patterns" - this is where you can adjust the automatic URL alias settings for your content. In the "Content Paths" section you'll see the default is set to "content[node:title]" -- just below that you'll want to set "Pattern for all Blog entry paths" to "contenta/[node:title]" and save your new configuration. This means all of your future Content A content will have URLs like: http://yoursite.com/contenta/your-contenta-title. 

(Thanks to Jonathan Webb http://www.drupalgardens.com/content/block-not-showing)

That should do it. 

This assumes that the user can only add one node. 

EDIT : An update with the requirement mentioned in the comment

Instead of step 1 and 2 do the following

1) Enable php filter

2) Create a view of the type block with just one field may be nid of the node. Remove the label. Rewrite the out put to some thing like  so that nothing is displayed.

3) Add contextual filter of the type content:author and select provide default value and from the drop down select User ID from logged in user

4) In the header section add a field of the type gloal:textarea click on "Display even if view has no result" so that it would be displayed even if there is no result.

5) Select PHP code as the filter and paste the following code with the changes that suite your requirement such as changing the url to the one that adds your content type.  

&lt;?php
  $view = views_get_current_view();

   if (!count($view-&gt;result))
   {
       print "&lt;a href='" . base_path() . "node/add/book'&gt;Add Node&lt;/a&gt;";
   }
?&gt;


Follow step 3 and 4 to add the block to the node.